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: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:
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 runningtsconfig.json provided by Hardhat:
2. Configure Hardhat automining
Then, open thehardhat.config.ts and replace the HardhatUserConfig object with this one:
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 acontracts subfolder in the project folder now, with a sample contract named Lock.sol. To compile this contract and verify its correctness, run
artifacts/contracts/Lock.sol/Lock.json. We will use this file in squid development.
4. Launch hardhat node
From the project root folder, run5. Deploy the contract
The node will keep the console window busy. In a different terminal, run this command: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 runbuild/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 thetruffle-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 thedevelopment section in truffle-config.js and setting its properties as follows:
Squid development
The indexing setup is ready to use. To test it, replace the contents ofsrc/main.ts with the following.
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.