Skip to content

Set up ETH Indexer ​

Requirements ​

  • A running ETH Tracker and its NATS server.
  • PostgreSQL 10 or later. The dev setup uses 16.
  • An RPC endpoint on the same chain, for token and pool metadata.
  • Go 1.26 with a C toolchain to build from source, or Docker.

Create the database ​

The indexer needs an existing database. For development, run PostgreSQL on 127.0.0.1:5433 with a chain_data database:

sh
git clone https://github.com/cosmo-local-credit/eth-indexer.git
cd eth-indexer
docker compose -f dev/docker-compose.postgres.yaml up -d

To keep the indexer in its own schema of a shared database, create the schema and add search_path to the DSN:

sql
CREATE SCHEMA indexer;
postgres://user:password@host:5432/chain_data?search_path=indexer

Configure ​

The indexer reads config.toml. Set -config to use another file. Environment variables with the INDEXER_ prefix override file values, with two underscores between section and key: INDEXER_POSTGRES__DSN sets postgres.dsn.

A value that contains a comma or a space becomes a list. Use URL-form DSNs in environment variables. A list with one item needs a trailing comma, such as nats://nats:4222,.

SettingWhat it controls
postgres.dsnPostgreSQL connection string.
jetstream.endpointNATS URLs, as a TOML array.
jetstream.idDurable consumer name. Keep it stable across restarts.
chain.rpc_endpointRPC URL for token and pool metadata.
chain.chainid100 for Gnosis.
api.addressListen address for /metrics.

A new jetstream.id creates a new consumer, which replays every event the stream still holds. The tracker keeps 48 hours by default (jetstream.persist_duration_hrs). Two instances with the same jetstream.id share the events between them.

FlagDefaultWhat it sets
-configconfig.tomlConfig file
-migrationsmigrations/Migrations directory
-queriesqueries.sqlSQL query file

Paths are relative to the working directory.

Run ​

From source:

sh
make build
./eth-indexer -config config.toml

With Docker:

sh
docker run -d --name eth-indexer \
  -v "$PWD/config.toml:/service/config.toml:ro" \
  -p 5002:5002 \
  ghcr.io/cosmo-local-credit/eth-indexer:<tag>

Each start runs any new migrations before it reads events. A migration that runs longer than 15 seconds fails startup.

Verify ​

The log prints migrations ran successfully, then connects to NATS. Check that rows arrive:

sql
SELECT count(*), max(block_number), max(date_block) FROM tx;

SELECT t.block_number, t.tx_hash, tt.contract_address, tt.transfer_value
FROM token_transfer tt
JOIN tx t ON t.id = tt.tx_id
ORDER BY t.block_number DESC
LIMIT 10;

Check the consumer's backlog with the NATS CLI:

sh
nats consumer info TRACKER eth-indexer-1

Operate ​

  • A restart resumes from the consumer's last acknowledged event.
  • Twenty workers process events at once, so rows are not written in block order.
  • If a handler fails, the event is redelivered at once and every handler for its subject runs again. The log shows handler error sending nack. An RPC outage causes repeated redelivery until the RPC is back.
  • Events for subjects with no handler are acknowledged and dropped.