Logging Events on Ethereum

A quick insight into dealing with Ethereum events for logging purposes.

Primoz Kocevar
VALUS
2 min readNov 12, 2018

--

OVERVIEW

When trying to look up some Ethereum Events using Web3.py for forwarding reasons I had some problems.

Why use events and how:

How to use Ethereum events with Python:

For our use-case, this is kind of useless as it requires a TX receipt which we do not have in our case (or in any case when you don't save a TX receipt, which is in most cases).

USING INFURA AND WSS

As it turns out you can not use an Infura HTTP api if you would like to listen to events but you must use Websocket as a Web3 provider!!! A big help if you want to do it using INFURA:

Also Infura documentation for EVENTS, HELPFUL:

FILTERING EVENTS

Filtering events proved to be more difficult than expected as the provided documentation is quite clumsy and there are a few helpful must-know tricks.

The official documentation here was bit unhelpful as it suggested to use fromBlock=’latest’ and using filter.get_new_enteries() :

This did not return any useful events as we should have used get_all_enteries(). As helpfully suggested here:

On Event Filters and how to use them:

In this present time 4.9.2018 it is unreliable to depend on the get_new_entries() function as filters have a problem with deleting:

Thus it is best to not rely on it and lookup if deposits are new by yourself locally! (looking up block numbers, or maybe id’s …)

PROBLEM with web3.py and websockets providers for INFURA is described here:

--

--