Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve docs for abi required-ness #3137

Merged
merged 7 commits into from
Nov 7, 2023

Conversation

reedsa
Copy link
Contributor

@reedsa reedsa commented Nov 1, 2023

What was wrong?

Lacking clarity on whether abi must be provided.

Closes #2539

How was it fixed?

Explicit docs for ABI being required for contract interactions to work.

Todo:

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

@reedsa reedsa requested review from fselmo and pacrob November 1, 2023 19:39
docs/web3.contract.rst Outdated Show resolved Hide resolved
@@ -1238,6 +1238,11 @@ Contracts

.. py:method:: Eth.contract(address=None, contract_name=None, ContractFactoryClass=Contract, **contract_factory_kwargs)

An ``abi`` specifies how a contract can be interacted with. The ``abi``
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this clarification should go down below, as in the "following arguments are accepted" section. This first section discusses the actual named arguments associated with the function, in order. abi, while necessary for making contract calls, isn't a named arg, just an optional kwarg (whether this is a good design is perhaps another question 🤔 ) Maybe adding it as a description to the optional kwargs list is a better place? That then opens it as a place for describing usage of the others in that list.

Just my feels, open for discussion!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be ideal to call something out here in the contract docs. I wonder if it would help to include abi as an argument in the method signature above, or some way of indicating it is necessary for the interface to work.

Agree this paragraph doesnt seem quite right in the contract API docs. I think it might clutter the list down below, but there is a link to the Contracts guide from there. I think the paragraph might be a good replacement for the contract docs under Contract.abi. What do you think?

Copy link
Contributor

@pacrob pacrob Nov 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with putting more info under Contract.abi. Could even explain what ABI stands for there. I also agree with some indication here that abi is required if you want to interact with the contract, maybe just not first thing?

- ``user_doc``

See :doc:`web3.contract` for more information about how to use contracts.
:param abi: Application Binary Interface. Usually provided since an ``abi`` is required to interact with any contract.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fselmo @pacrob I like the sphinx param block! I'm not sure about all of these params, but I took my best guess at as many as I could. Are there any words we can add or change here?

Thanks!

Copy link
Collaborator

@fselmo fselmo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing holding this back really. Good updates. Just some food for thought.

:param decode_tuples: Optionally convert tuples/structs to named tuples
:param interface:
:param metadata: Contract Metadata generated by the compiler
:param opcodes: Opcodes of the contracts generated by the compiler
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
:param opcodes: Opcodes of the contracts generated by the compiler
:param opcodes: Opcodes for the contract generated by the compiler

Is this meant to be singular here?

:param user_doc:
:return: Instance of the contract
:rtype: Contract
:raises TypeError: if the address is not provided
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
:raises TypeError: if the address is not provided
:raises TypeError: If the address is not provided

Everything else seems to be capitalized here.

:return: Instance of the contract
:rtype: Contract
:raises TypeError: if the address is not provided
:raises AttributeError: if the contract class is not initialized
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
:raises AttributeError: if the contract class is not initialized
:raises AttributeError: If the contract class is not initialized

@@ -0,0 +1 @@
Additional contract ``abi`` documentation to make it a clear requirement for contract instances.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Additional contract ``abi`` documentation to make it a clear requirement for contract instances.
Additional contract ``abi`` documentation to make it a clear requirement for interacting with contract instances.

Perhaps that distinction? Are we allowed to create a contract instance without an ABI? I'm not at my computer at the moment to verify but, if so, is there a particular reason we even allow that and don't validate it as an input to __init__()?

Just curious on improvements that could come in v7 but also maybe we should clarify the exceptions in the docs as well, if they exist.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recall an example that used a contract without an abi, I'll dig it up in the docs in a bit. It is possible to create, though very limited in what it can do.

I have no clear idea why it isn't enforced but maybe it is so that really basic operations can be done.maybe comparing contract instances or something?

@reedsa reedsa merged commit 48a753c into ethereum:main Nov 7, 2023
89 checks passed
@reedsa reedsa deleted the contract-abi-required branch November 7, 2023 23:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

web3.eth.contract with no abi
3 participants