web3.py: AttributeError: 'Contract' object has no attribute 'eventFilter'
- Python: 2.7
- OS: osx
Goal: I want to print logs of the smart contract, like I do on web3.js
, using web3.py
.
On web3.js
side, following code piece works:
var event = myContract.LogJob({}, {fromBlock:0, toBlock:'latest'});
event.watch(function(error, result) {
console.log(JSON.stringify(result));
});
But on the web3.py
side I was not able to make it work. 😦 I have followed following documentation.
event_filter = myContract.eventfilter('LogJob', {'filter': {'arg1':10}})
Error I am having:
AttributeError: 'Contract' object has no attribute 'eventFilter'
I have also tried following line of code, but it did not worked as well:
event = myContract.call().LogJob({}, {'fromBlock':100, 'toBlock':110});
[Q] Am I doing something wrong? How could I fix this?
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 18 (6 by maintainers)
cc @dylanjw and @carver
Would be good for us to try and figure out a practical way to have notes like “added in 4.0” like I’ve seen in django and the python standard library documentation.
New question: https://ethereum.stackexchange.com/q/43642/4575 @carver
Your last comment is the same as this issue: https://github.com/ethereum/web3.py/issues/699, and shows that our documentation needs to be fixed. Our example has
_from
in the filter arguments, that makes it seem like that is the way to filter for the emanating contract, rather than what it is, an argument specific to the example event.Because your
LogCluster
event has no_from
argument, the web3 abi lookup doesnt find an event abi that matches the argument and event name combination.In other words, the
filter
argument dict can be used to match events with the given argument values. Based on your event ABI and example code, that might look like this:If you just want all logs emanating from that event, just delete the filter parameter.
@avatar-lavventura Have a look at the web3.py docs, specifically on filters and contracts. The contract class does not implement an “on” method, like you may be used to in web3.js (or js in general).
Callbacks are one pattern for building asynchronous programs. There are other patterns as well. Take a look at http://web3py.readthedocs.io/en/stable/filters.html#asynchronous where we give examples for how you might implement asynchronous filter polling in your code, if that is what you are after.
Yes I verify that there is an
event
with the name LogCluster.On
web3.js
side following code works:ABI: https://gist.github.com/avatar-lavventura/c45ad830700a9d19cd0e9c1ce417c380