Date: 2018-11-20 21:23:51
Logging Events on Ethereum
Logging Events on Ethereum

Logging Events on Ethereum

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

OVERVIEW

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

Why even use events and how:

How to do it in python:

but 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:

Designed and Developed with ♥︎
Copyright © 2018 VALUS - All Rights Reserved