Let's say we have 1000 contracts with the same type of event 'Event'. I can subscribe to each one of them individually using contract.listen('Event'), but I cannot use this if I want to create a single handshake that sends me every 'Event' happening in each of them. For that I would need to create 1000 contracts and then call .listen('Event') a 1000 times.

Is there a way to do something like w3.listen([contracts],'Event')? Or some feasible way to subscribe to so many contracts at the same time?


2 Answers 2


The best way to is to listen for the event topic signature for all new events the signature in all new blocks. I believe you can do this with a single filter. Then you filter it out on the application side if the event is not part of a contract set you are interested in.

  • Thanks! I managed to do it, will put now an answer with the code I'm using
    – Hiperfly
    Commented Apr 20, 2021 at 19:41

I made it following the suggestion of Mikko. Here is the piece of code I used (I'm using Infura so I cannot directly use filters):

async def event_filter(list_of_pools,list_of_topics):
    msg_events = {"id": 1, "method": "eth_subscribe", "params": ["logs", {"address":list_of_pools, "topics": list_of_topics}]}
    async with websockets.connect(API) as ws:
        await ws.send(json.dumps(msg_events))
        while ws.open:
            response = json.loads(await ws.recv())

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.