web3.py: Events filtering not working with EIP checksum addresses (Ganache-CLI)
- Version: 4.0.0b10 - 4.1.0
- Python: 3.5
- OS: linux
What was wrong?
Maybe the issue is not exactly web3.py related, but when using EIP-55 checksum addresses event filtering is not working. My guess is that the reason is that Ganache-CLI is not producing proper addresses.
Event Filter done as follows:
certificate_created_filter = instance.eventFilter(
'CertificateCreated',
{
'fromBlock': 0,
'toBlock': 'latest',
})
loop = asyncio.get_event_loop()
try:
task = loop.create_task(
self.log_loop(certificate_created_filter, 0.5))
loop.run_until_complete(task)
finally:
loop.close()
Checking for events
async def log_loop(self, event_filter, poll_interval):
event_filter.get_all_entries()
while True:
for event in event_filter.get_new_entries():
self.handle_event(event)
await asyncio.sleep(poll_interval)
Not Working:
for _, network in contract_interface['networks'].items():
_contracts[contract_name] = w3.eth.contract(
address=web3.Web3.toChecksumAddress(network['address']),
abi=contract_interface['abi'])
return _contracts[contract_name]
Working (with monkey patched web3.utils.validation.validate_address):
for _, network in contract_interface['networks'].items():
_contracts[contract_name] = w3.eth.contract(
address=network['address'], # Address all lowercased
abi=contract_interface['abi'])
return _contracts[contract_name]
The monkey patch is to simply ignore the EIP checksum validation.
How can it be fixed?
Not sure what is the best way to fix it. Simply ignoring checksum validation seems not right. I’m glad to discuss.
editor: Let’s add an optional middleware that can be injected to the innermost layer that forces all hex to lowercase, similar to the geth_poa_middleware
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 1
- Comments: 15 (4 by maintainers)
Commits related to this issue
- Monkey patch for #674 and for PR #827 — committed to gakonst/web3.py by gakonst 6 years ago
@carver Working, thank you!
I’m still having this issue with:
The following filter does not work:
but this does:
Where
contract.address
is checksummed.Filtering events in ganache from web3 is broken. I submitted a fix and am waiting for it to get merged and included in ganache -> https://github.com/MetaMask/provider-engine/pull/280
@kfichter
This was marked resolved in ganache-core@2.1.3 and ganache-cli@6.1.4
Can you upgrade and try again?
If you’re dealing with this error consider speaking up in the following github issue in the ganache codebase.
https://github.com/trufflesuite/ganache-cli/issues/494