Events – `web3.py`: AttributeError: ‘Contract’ Object Has No Attribute ‘eventFilter’

eventsweb3.py

Update:

For web3 v5.x.x,

Event Log Filters is as follows:

event_filter= myContract.events.<event_name>.createFilter(fromBlock="latest", argument_filters={'arg1':10}) 
event_filter.get_new_entries()

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?

Best Answer

You're trying to use a v4 feature. Chances are good that you have v3 installed. To install the latest v4 version, use:

pip3 install --upgrade web3