-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Description
What was wrong?
No easy way to get all events for a contract (while still parsing the results). See this StackExchange question. One option is to iterate over all the events, but it's a bit awkward right now. I think the easiest way is:
from web3.contract import ContractEvent
filters = [
event.createFilter(fromBlock='latest')
for event in myContract.events
if isinstance(event, ContractEvent)
]How can it be fixed?
Some options:
- Implement
__iter__onContract.eventsto iterate through all events in the ABI (my favorite option, except that it's inconsistent withcontract.functions, which is doing the wrong thing IMO) - Add a new
Contract.all_events()equivalent toContract.all_functions()
Then the example changes to:
filters = [
event.createFilter(fromBlock='latest')
for event in myContract.events
]Of course, we could also implement contract.create_filter() like web3.js's contract.events.allEvents. I kind of like that the filters are event specific right now, though. I don't think it's too big a deal to require callers to write a filter loop on events.
conlan, HarryR and jpiabrantes