Skip to content

Commit

Permalink
Add section to ambiguous section of the contract docs
Browse files Browse the repository at this point in the history
  • Loading branch information
reedsa committed Sep 13, 2024
1 parent e1d16e5 commit 233fa23
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion docs/web3.contract.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1450,6 +1450,23 @@ You can interact with the web3.py contract API as follows:
Invoke Ambiguous Contract Functions
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Calling overloaded functions can be done as you would expect. Passing arguments will
disambiguate which function you want to call.

For example, if you have a contract with two functions with the name ``identity`` that
accept different types of arguments, you can call them like this:

.. code-block:: python
>>> ambiguous_contract = w3.eth.contract(address=..., abi=...)
>>> ambiguous_contract.functions.identity(1, True).call()
1
>>> ambiguous_contract.functions.identity("one", 1, True).call()
1
If there is a need to first retrieve the function, you can use the contract instance's
``get_function_by_signature`` method to get the function you want to call.

Below is an example of a contract that has multiple functions of the same name,
and the arguments are ambiguous. You can use the :meth:`Contract.get_function_by_signature`
method to reference the intended function and call it with the correct arguments.
Expand All @@ -1468,7 +1485,6 @@ method to reference the intended function and call it with the correct arguments
}
"""
# fast forward all the steps of compiling and deploying the contract.
>>> ambiguous_contract.functions.identity(1, True) # raises Web3ValidationError
>>> identity_func = ambiguous_contract.get_function_by_signature('identity(uint256,bool)')
>>> identity_func(1, True)
Expand Down

0 comments on commit 233fa23

Please sign in to comment.