Skip to main content

Objective

Here we show how it is possible to index an Ethereum development node running locally. This is useful for those who want to start developing a squid ETL or API in a local environment without waiting for the contract to be deployed to a testnet.

Pre-requisites

Setup

In this tutorial we will be using a layout in which the squid and the Hardhat/Ganache setup share the same folder. Create a new squid by running:
Here, ethereum-local-indexing is the project name and evm refers to the evm template. Install the dependencies, then add the packages of the EVM RPC data source:
Local development chains have no SQD Network Portal dataset, so instead of the template’s Portal-based DataSourceBuilder we will use EvmRpcDataSourceBuilder to ingest data straight from the local node’s JSON-RPC endpoint. Its query surface is identical, and the built source runs with the usual run() from @subsquid/batch-processor. Next, we set up a local EVM development environment. We consider two common options: Hardhat and Ganache.

If you chose Hardhat

Install the package.

1. Create project

In a terminal, navigate to the squid project root folder. Prepare it by running
This will prevent collisions between SQD and Hardhat files. Next, run
to initialize the Hardhat project. When prompted, choose TypeScript project and keep all other options at defaults. Finally, overwrite tsconfig.json provided by Hardhat:

2. Configure Hardhat automining

Then, open the hardhat.config.ts and replace the HardhatUserConfig object with this one:
The mining configuration will continuously mine blocks, even if no events or transactions are executed. This can be useful for debugging. You can read more about it on hardhat official documentation.

3. Sample contract

There should be a contracts subfolder in the project folder now, with a sample contract named Lock.sol. To compile this contract and verify its correctness, run
You should find the contract’s ABI at artifacts/contracts/Lock.sol/Lock.json. We will use this file in squid development.

4. Launch hardhat node

From the project root folder, run

5. Deploy the contract

The node will keep the console window busy. In a different terminal, run this command:
If the contract deployed successfully, the output should look like
Take note of the contract address, you’ll need it later.

If you chose Ganache

Install Truffle and Ganache packages.

1. Truffle project, sample contract

Let’s create a new truffle project with a sample contract. In the project main folder run
Compile the contracts with
You should find the contract’s ABI at build/contracts/MetaCoin.json. It will be useful for indexing.

2. Create a workspace

Launch the Ganache tool and select the New Workspace (Ethereum) option. Next, provide a name for the workspace and link the Truffle project we just created to it. To do that, click Add project and select the truffle-config.js file in the project root folder. Finally, select the Server tab at the top. In this window, set HOSTNAME to 127.0.0.1, PORT NUMBER to 8545 and NETWORK ID to 1337, and disable the AUTOMINE option to ease the debugging. Finally, click “Start” to launch the blockchain emulator.

3. Deploy a smart contract

Configure Truffle by uncommenting the development section in truffle-config.js and setting its properties as follows:
Deploy the sample smart contract by running
Log information similar to this should be displayed:
Take note of the contract address, you’ll need it later.

Squid development

The indexing setup is ready to use. To test it, replace the contents of src/main.ts with the following.
This defines a squid that retrieves all chain transactions from the local node RPC endpoint without filtering, making sure to retrieve the addresses of the deployed contracts for deployment transactions.
A local chain has no network preset, so the data source logs a warning at build time about dataset parity with the Portal not being guaranteed. For local development this warning is expected and harmless.
Run the squid with
You should see the data of one (for Hardhat) or two (for Truffle+Ganache) contract deployment transactions printed to your terminal. Now you can develop a SQD-based indexer alongside your contracts. Head over to the dedicated tutorial for guidance on squid development. Use the contract’s ABI (here or here) and contract address (here and here) from previous steps and be mindful that the data source needs to point at the local node RPC endpoint, as in the example above:
You can also set the data source through an environment variable like it is done in this complete end-to-end project example (outdated, but still useful). This will make sure the project code stays the same and only the environment variables change depending on where the project is deployed.