You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
for ev in ["TransferSingle", "TransferBatch"]:
contract = w3.eth.contract(address=mycontract_address, abi=mycontract_abi)
# the below should work but for some reason does not:
#event_filter = contract.events.__getattr__(ev).createFilter(fromBlock=mycontract_deployblock, toBlock="latest")
event_filter = None
for cevent in contract.events:
if cevent.event_name == ev:
event_filter = cevent.createFilter(fromBlock=mycontract_deployblock, toBlock="latest")
break
This works for TransferSingle, but for TransferBatch it fails like this:
Traceback (most recent call last):
File "./mycode-rest.py", line 2080, in check_background_threads
event_filter = cevent.createFilter(fromBlock=mycontract_deployblock, toBlock="latest")
File "/mnt/dev/project/rest-backend/venv/lib/python3.7/site-packages/eth_utils/decorators.py", line 20, in _wrapper
return self.method(objtype, *args, **kwargs)
File "/mnt/dev/project/rest-backend/venv/lib/python3.7/site-packages/web3/contract.py", line 1158, in createFilter
log_filter = filter_builder.deploy(self.web3)
File "/mnt/dev/project/rest-backend/venv/lib/python3.7/site-packages/web3/_utils/events.py", line 397, in deploy
for arg in self.args.values():
TypeError: 'DataArgumentFilter' object is not callable
Now, TransferBatch is specified like this: event TransferBatch(address indexed _operator, address indexed _from, address indexed _to, uint256[] _ids, uint256[] _values);
Note the arrays for _ids and _values - I suspect that's what causes the error, as the same code has worked fine for me for all kinds of events so far, but none had arrays in it before this one.
How can it be fixed?
Not sure, I know too little of handling events in the guts of web3.py to speculate on that.
The text was updated successfully, but these errors were encountered:
I have worked around this for the moment with a generic web3.eth.filter() on the topic, which I read out of the contract's .json file and then dedode the arguments from the event's data field via eth_abi.decode_single() but this is pretty cumbersome code when it should be supported straight-forward by web3.py instead.
pip freeze
outputWhat was wrong?
I'm trying to set up event filters for ERC 1155 transfer events (see https://eips.ethereum.org/EIPS/eip-1155#specification for the spec) with code like this (simplified):
This works for TransferSingle, but for TransferBatch it fails like this:
Now, TransferBatch is specified like this:
event TransferBatch(address indexed _operator, address indexed _from, address indexed _to, uint256[] _ids, uint256[] _values);
Note the arrays for _ids and _values - I suspect that's what causes the error, as the same code has worked fine for me for all kinds of events so far, but none had arrays in it before this one.
How can it be fixed?
Not sure, I know too little of handling events in the guts of web3.py to speculate on that.
The text was updated successfully, but these errors were encountered: