[Ethereum] How to read “allevents” using Python web3 (there’s capability in web3.js)

contract-developmenteventspython

Is there a mechanism to create a listener for all events being emitted from a smart contract for the python web3 library. There is a way to do it in web3.js:

myContract.events.allEvents([options][, callback])

However, I don't see a parallel in Python's library. There is a function to get all of the events in Hex but I am looking for the human readable version.

How to get events in Hex:

event_filter = web3.eth.filter({"address": contract_address})

web3.js documentation: https://web3js.readthedocs.io/en/1.0/web3-eth-contract.html#events-allevents
web3.py documentation: http://web3py.readthedocs.io/en/stable/filters.html

Best Answer

One option is to iterate all events and call createFilter on each of the events. Something like:

from web3.contract import ContractEvent

filters = [
  event.createFilter(fromBlock='latest')
  for event in myContract.events
  if issubclass(event, ContractEvent)
]
Related Topic