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:
git clone https://github.com/cosmo-local-credit/eth-indexer.git
cd eth-indexer
docker compose -f dev/docker-compose.postgres.yaml up -dTo keep the indexer in its own schema of a shared database, create the schema and add search_path to the DSN:
CREATE SCHEMA indexer;postgres://user:password@host:5432/chain_data?search_path=indexerConfigure
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,.
| Setting | What it controls |
|---|---|
postgres.dsn | PostgreSQL connection string. |
jetstream.endpoint | NATS URLs, as a TOML array. |
jetstream.id | Durable consumer name. Keep it stable across restarts. |
chain.rpc_endpoint | RPC URL for token and pool metadata. |
chain.chainid | 100 for Gnosis. |
api.address | Listen 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.
| Flag | Default | What it sets |
|---|---|---|
-config | config.toml | Config file |
-migrations | migrations/ | Migrations directory |
-queries | queries.sql | SQL query file |
Paths are relative to the working directory.
Run
From source:
make build
./eth-indexer -config config.tomlWith Docker:
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:
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:
nats consumer info TRACKER eth-indexer-1Operate
- 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.