3

I've following code to obtain new event entries. The idea is to get latest Transfer events from a specific contract.

from web3 import Web3, HTTPProvider
import json

abi = json.load(open('abi.json'))
address = '0x.....................'

w3 = Web3(HTTPProvider('http://localhost:8545'))

contract = w3.eth.contract(abi=abi,address=address)

event_filter = contract.eventFilter('Transfer',{'fromBlock':0,'toBlock':'latest'})

logs = event_filter.get_new_entries()

print(logs);

There is a local ethereum node running under port 8545 with --rpc.

When I run above script after initiating a transaction, it always prints an empty array.

If I change it to event_filter.get_all_entries() I can see all the transactions. But get_new_entries() doesn't work. Any idea what would be the issue?

1 Answer 1

2

If I change it to event_filter.get_all_entries() I can see all the transactions. But get_new_entries() doesn't work. Any idea what would be the issue?

As I can see from web3.py latest documentation:


The function LogFilter.get_all_entries() is returning all logs which match the filter

Logs will be retrieved using the web3.eth.Eth.getFilterLogs() which returns all logs that match the given filter.


From the other side we have LogFilter.get_new_entries() which returns only new entries since the last poll.

Logs will be retrieved using the web3.eth.Eth.getFilterChanges() which returns only new entries since the last poll.


Summarizing.

If you haven't called this method before, it cannot decide which entries are new, so it returns undefined. You should first call LogFilter.get_all_entries() and only after you called it and some changes happened call LogFilter.get_new_entries().

Returns all new entries which occurred since the last call to this method for the given filter_id


Event Log Filters

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.