- Web3.py version 4.2.1
- geth version:
1.8.0-unstable
I have followed web3.py guide for filtering.
Through the contract instance api:
event_filter = mycontract.events.myEvent.createFilter(fromBlock='latest', {'filter':{'arg1':10}})
But I get an error for this line:
myContract.events.LogJob.createFilter(fromBlock='latest', {'filter': {'arg1':10}})
My main goal is the filter events based on their arguments.
Error I am having:
myContract.events.LogJob.createFilter(fromBlock='latest', {'filter': {'arg1':10}})
^
SyntaxError: positional argument follows keyword argument
[Q] How could I fix this error?
Update: I have followed @Mikko Ohtamaa 's answer. Now I do not get any error, but filter returns []
even I provide correct event's keyword (dictionary of argument name and its value).
Please see an example:
blockReadFrom = 1899201;
myFilter = eBlocBroker.events.LogJob.createFilter(fromBlock=blockReadFrom)
print(myFilter.get_all_entries())
Returns, here you can see that there is emitted event with 'storageID': 0
under AttributeDict
:
[AttributeDict({'address': '0x128c9F368F12C24Cc2a4f88dCDCf3daA13C9667e', 'transactionHash': HexBytes('0x8f7c50fe276057ea90985be6d14dc7abb79ee0430c66bd161861b582b7db0c97'), 'args': AttributeDict({'desc': 'Science', 'jobKey': 'QmRsaBEGcqxQcJbBxCi1LN9iz5bDAGDWR6Hx7ZvWqgqmdR', 'index': 21, 'storageID': 0, 'clusterAddress': '0x75A4c787c5c18C587B284a904165Ff06a269B48C'}), 'transactionIndex': 0, 'event': 'LogJob', 'blockHash': HexBytes('0x9782cb281aa72defe54e0f84055a03a0b1bf6c6f21bd3d276a1252098f83c15f'), 'logIndex': 0, 'blockNumber': 1899201})]
blockReadFrom = 1899201;
myFilter = eBlocBroker.events.LogJob.createFilter(fromBlock=blockReadFrom, argument_filters={'storageID':0})
print(myFilter.get_all_entries())
Returns:
[]
And interesting point that following line returns a valid output even though {'arg1': 999
or 'arg111': 999
etc.} does not exists.
myFilter = eBlocBroker.events.LogJob.createFilter(fromBlock=blockReadFrom, argument_filters={'arg1': 999})
Note:
For more information please follow this closed issue: https://github.com/ethereum/web3.py/issues/943#event-1723643072