Web3.py – How to Create Event Filter in Python 3 via createFilter

filterspythonsolidityweb3.py

According to the Web3.py Documentation: http://web3py.readthedocs.io/en/latest/filters.html

Quote "event_filter = contract.events.myEvent.createFilter(fromBlock='latest', {'filter': {'arg1':10}})"

                                                              ^

Then I got: "SyntaxError: positional argument follows keyword argument"

Then I removed "fromBlock='lastest',"

event_filter = contract.events.myEvent.createFilter({'filter': {'arg1':10}})

Then I got: "TypeError: createFilter() takes 1 positional argument but 2 were given"

Ok… then I Googled that…
https://stackoverflow.com/questions/23944657/typeerror-method-takes-1-positional-argument-but-2-were-given

let's try: my_new_object = cInst.events()

Then I got "TypeError: 'ContractEvents' object is not callable"

Does this web3.py Documentation work at all??? I am so disappointed… 🙁

Please help. Thank you

Best Answer

You can use the following method in web3py to get events:

myfilter = mycontract.eventFilter('EventName', {'fromBlock': 0,'toBlock': 'latest'});
eventlist = myfilter.get_all_entries()

eventlist will be a list of dictionaries containing the parameters of each event that had happened.

Hope this helps.