You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I found a contract in the wild that I couldn't instantiate with web3.py (0x480de54f42b17d459314f9D76cAa1A531B43c240).
It seems that this is because the contract includes a function named "w3", which overwrites the w3 member on the ContractCaller class meaning the class can't use it internally when it tries to create any further contract members.
Traceback (most recent call last):
File "testcaseweb3.py", line 33, in <module>
failing = w3.eth.contract(address=address, abi=failing_abi)
File "web3.py/web3/eth/eth.py", line 652, in contract
ContractFactory = ContractFactoryClass.factory(self.w3, **kwargs)
File "web3.py/web3/contract/contract.py", line 320, in factory
contract.caller = ContractCaller(
File "web3.py/web3/contract/contract.py", line 585, in __init__
block_id = parse_block_identifier(self.w3, block_identifier)
File "web3.py/web3/_utils/contracts.py", line 417, in parse_block_identifier
return w3.eth.default_block
AttributeError: 'functools.partial' object has no attribute 'eth'
What type of node you were connecting to.
HTTPProvider (quicknode)
How can it be fixed?
The ContractCaller constructor sets the names it finds in the abi on the class itself in this line:
setattr(self, func["name"], caller_method)
If the ABI includes an identifier named "w3" this overrides the existing variable on the class named "w3" so when the code next tries to use this in contract.py#585 we get an AttributeError: 'functools.partial' object has no attribute 'eth'.
I've written a test case to demonstrate this and created a PR with an attempted fix.
The text was updated successfully, but these errors were encountered:
What was wrong?
I found a contract in the wild that I couldn't instantiate with web3.py (0x480de54f42b17d459314f9D76cAa1A531B43c240).
It seems that this is because the contract includes a function named "w3", which overwrites the w3 member on the ContractCaller class meaning the class can't use it internally when it tries to create any further contract members.
HTTPProvider (quicknode)
How can it be fixed?
The ContractCaller constructor sets the names it finds in the abi on the class itself in this line:
setattr(self, func["name"], caller_method)
If the ABI includes an identifier named "w3" this overrides the existing variable on the class named "w3" so when the code next tries to use this in contract.py#585 we get an
AttributeError: 'functools.partial' object has no attribute 'eth'
.I've written a test case to demonstrate this and created a PR with an attempted fix.
The text was updated successfully, but these errors were encountered: