2

Using Web3.py I understand that I can create a new smart contract event filter with:

Contract.events.your_event_name.createFilter(fromBlock=block, toBlock=block, argument_filters={'arg1': 'value'}, topics=[])

I want to listen for multiple smart contract events. My proposed solution is to use threads.

client = Web3Client(nodeUri=nodeUri)
event1 = client.contract.events.your_event_name()
block_filter1 = event.createFilter(fromBlock="latest")
worker1 = Thread(target=log_loop, args=(block_filter1, 5), daemon=True)
worker1.start()
event2 = client.contract.events.another_event_name()
block_filter2 = event.createFilter(fromBlock="latest")
worker2 = Thread(target=log_loop, args=(block_filter2, 5), daemon=True)
worker2.start()

Is it possible to filter for multiple your_event_name(s) in one filter? Or is the best practice to use threads?

0

Your Answer

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

Browse other questions tagged or ask your own question.