# Run the Indexer

### Quickstart

<figure><img src="/files/8xyTTj4gpldrboNxoAZR" alt=""><figcaption><p>How it works</p></figcaption></figure>

**Prerequisites**

Ensure you have the following installed:

* Docker
* Docker Compose

**Step-by-Step Instructions**

1. **Prepare Environment Variables**
   * Copy the `env.sample` file and rename it to `.env`.
   * Edit the `.env` file to set the following variables according to your needs:
     * `CHAIN_ID`: The ID of the blockchain network you are indexing.
     * `DATABASE`: The name of the database that will be created in ClickHouse.
     * `PROVIDER_URL`: The URL of your RPC provider, such as a public node, Infura, or a local node.
   * See [Environment Variables](broken://pages/6fCAFM5Si7d2PUW4qnoe)
2. **Start Indexing**
   * Open your terminal and navigate to the directory containing your `docker-compose.yml` file.
   * Run the command:

     ```sh
     docker-compose up
     ```
   * This command will start indexing the Ethereum blockchain into ClickHouse.
3. **Verify Database Content**
   * Once the indexing process begins, you can inspect the database to see the tables created for each entity type and a few service-related tables.

#### Running certain command

Install Ethereum ETL:

```
pip3 install -r requirements.txt
```

:warning: If you want to use Clickhouse as a destination, make sure to apply migrations:

```
CLICKHOUSE_URL=clickhouse+http://default:@localhost:8123/ethereum alembic upgrade head 
```

Export blocks and transactions ([Schema](https://github.com/dex-guru/ethereum-etl/blob/main/db/migrations/schema.sql), [Reference](https://github.com/dex-guru/ethereum-etl/blob/main/docs/commands.md#export_blocks_and_transactions)):

```
ethereumetl export_blocks_and_transactions --start-block 0 --end-block 500000 \
--blocks-output blocks.csv --transactions-output transactions.csv \
--provider-uri https://mainnet.infura.io/v3/${INFURA_API_KEY}
```

Export ERC20 and ERC721 transfers ([Schema](https://github.com/dex-guru/ethereum-etl/blob/main/docs/schema.md#token_transferscsv), [Reference](https://github.com/dex-guru/ethereum-etl/blob/main/docs/commands.md##export_token_transfers)):

```
ethereumetl export_token_transfers --start-block 0 --end-block 500000 \
--provider-uri file://$HOME/Library/Ethereum/geth.ipc --output token_transfers.csv
```

Export traces ([Schema](https://github.com/dex-guru/ethereum-etl/blob/main/docs/schema.md#tracescsv), [Reference](https://github.com/dex-guru/ethereum-etl/blob/main/docs/commands.md#export_traces)):

```
ethereumetl export_traces --start-block 0 --end-block 500000 \
--provider-uri file://$HOME/Library/Ethereum/parity.ipc --output traces.csv
```

***

Stream blocks, transactions, logs, token\_transfers continually to console ([Reference](https://github.com/dex-guru/ethereum-etl/blob/main/docs/commands.md#stream)):

```
ethereumetl stream --start-block 500000 -e block,transaction,log,token_transfer --log-file log.txt \
--provider-uri https://mainnet.infura.io/v3/7aef3f0cd1f64408b163814b22cc643c
```

Find other commands [here](https://github.com/dex-guru/ethereum-etl/blob/main/ethereumetl/cli).

Supported export destinations [here](broken://pages/6fCAFM5Si7d2PUW4qnoe#output).

### Linters/formatters

#### Install

```
pip install black ruff mypy
```

#### Run

all-at-once run and fix:

```
ruff check --fix . && black . && mypy .
```

Or one-by-one:

* Check and auto-fix with: `ruff --fix .`
* Check typing: `mypy .`
* Auto-format all: `black .`

### Useful Links

* [Schema](https://github.com/dex-guru/ethereum-etl/blob/main/db/migrations/schema.sql)
* [Command Reference](https://github.com/dex-guru/ethereum-etl/blob/main/docs/commands.md)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.gurunetwork.ai/framework/indexer/run-the-indexer.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
