Search code examples
pythonwebsocketethereumweb3py

How to listen for events in Python with Infura (2019 year end)?


web3py 5.3.0 latest doc gives example of eventFilter --

https://web3py.readthedocs.io/en/latest/contracts.html#event-log-object

transfer_filter = my_token_contract.eventFilter('Transfer', 
    {'filter': {'_from': '0xDc3A9Db694BCdd55EBaE4A89B22aC6D12b3F0c24'}})

which results in error --

*** AttributeError: 'Contract' object has no attribute 'ContractEvents'

While I have raised this issue to web3.py on github --

https://github.com/ethereum/web3.py/issues/1508

Can someone please share working example of listening to Ethereum events in Python with Infura websocket, which does not support createFilter?


Solution

  • Thanks to kclowes at web3.py for pointing out that createFilter is indeed supported by Infura websocket, for which I've confirmed with my test.

    The issue on github has been updated --

    https://github.com/ethereum/web3.py/issues/1508