Indexer for the ethereum blockchain
eth-index is an indexer for events on the ethereum blockchain. It imports events into a postgresql database. It’s a companion to the trustlines project relay server component.
Before trying to install py-eth-index, make sure you have the postgresql development header files and library installed. On debian based systems this can be done by running:
apt install libpq-dev
eth-index uses python 3.6 or up. Please make sure you have the required version installed.
Please checkout the source code from github, cd into the checked out repo and run the folllowing pip command with a fresh virtualenv:
pip install -c constraints.txt .
A complete development environment can be installed with:
pip install -c constraints.txt -r requirements.txt pip install -c constraints.txt -e .
This installs black, flake8, mypy and tox among other things.
The source code is formatted with black. If you choose not to use the pre-commit hook, you should be able to format the source code with black setup.py src.
We use flake8 to check for errors. Run flake8 src to check for errors.
mypy is used to check for type errors. Run mypy --ignore-missing-imports src to check manually.
Running tox will run black, flake8, mypy and pytest locally.
Since we also do run some tests for postgres, the postgres database server must be installed on the local machine. It doesn’t have to be started though, since the tests do start postgres with a temporary data directory.
On a debian based system apt install postgresql will install the postgresql database.
The repository comes with a configuration file for pre-commit. pre-commit will be installed as part of the development dependencies specified in requirements.txt. The git commit hooks can be activated with pre-commit install inside the py-eth-index repository.
Initializing the database
Please setup a working postgres environment, i.e. set the PG* environment variables and configure ~/.pgpass.
to create the database tables.
ethindex is a command line program that is being used to run the actual syncing process. It also uses the PG* variables in order to determine the postgres server to connect to.
Before importing events into the postgres database, the ABIs must be known.
ethindex importabi can be used to import ABIs into the postgres database. By default it reads two json files addresses.json and contracts.json from the current directory and adds them to the abis table. These files are the exact files that the relay server also reads. Their location can be specified via the --addresses and -contracts command line arguments.
Usage: ethindex importabi [OPTIONS] Options: --addresses TEXT --contracts TEXT --help Show this message and exit.
ethindex runsync will start the actual synchronization process. On the first start it will read all of the abis and create one entry in the sync table containing all contract addresses. It then imports all of the events into the postgres table events.
Usage: ethindex runsync [OPTIONS] Options: --jsonrpc TEXT jsonrpc URL to use --required-confirmations INTEGER number of confirmations until we consider a block final --waittime INTEGER time to sleep in milliseconds waiting for a new block --startblock INTEGER Block from where events should be synced --syncid TEXT syncid to use --merge-with-syncid TEXT syncid to merge with --help Show this message and exit.
Adding new contracts
Import the contracts using the ethindex importabi command. Then synchronize these contracts and merge them with the default syncid with something like the following command:
ethindex runsync --syncid new --merge-with-syncid default
This command will synchronize all contracts, which aren’t already synchronized for the default syncid and will merge the new syncid into the default syncid, when both of them are fully synchronized with the chain. This means that a runsync job has to be running for default.
Status and Limitations
- ethindex is alpha software.
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size eth_index-0.3.2-py3-none-any.whl (10.9 kB)||File type Wheel||Python version py3||Upload date||Hashes View|
|Filename, size eth-index-0.3.2.tar.gz (22.7 kB)||File type Source||Python version None||Upload date||Hashes View|
Hashes for eth_index-0.3.2-py3-none-any.whl