HardHat

This guide walks you through setting up a complete local Ethereum development environment for Substreams development using HardHat. You'll deploy a sample Counter contract, generate transactions, and stream the events using Substreams.

Estimated time: 15-20 minutes

What You'll Build

  • Local Ethereum node (Geth in dev mode)

  • Firehose integration for block streaming

  • Counter smart contract with events

  • Substreams module to extract contract events

  • Complete Docker Compose orchestration

Prerequisites

Ensure you have the following installed:

  • Docker 20.10+ with Docker Compose v2.0+

  • Node.js 18+ with npm or yarn

  • Substreams CLI v1.7.0+ (installation guide)

  • Rust with wasm32-unknown-unknown target

  • curl for testing endpoints

Architecture Overview

The local environment consists of:

  • Geth (port 8545/8546) - Ethereum node in dev mode with 1-second block time

  • Substreams (port 9000) - Substreams Tier1 service providing gRPC streaming

  • Docker network - Connecting all services

Setup Instructions

1. Create Project Directory

2. Create Docker Compose Configuration

Create a docker-compose.yml file:

3. Start the Environment

Validation Commands

1. Check Docker Services

Verify all containers are running and healthy:

Expected output:

2. Test Substreams Connectivity

Test Substreams Tier1 gRPC connectivity:

Expected output:

Deploy Counter Contract with HardHat

1. Initialize HardHat Project

This guide mostly follows HardHat's setup tutorial in a streamlined way.

Follow the interactive prompts:

  • First choose Hardhat 3 Beta (recommended for new projects)

  • Second use . as the relative path

  • Third choose A TypeScript Hardhat project using Node Test Runner and Viem

  • Fourth choose Yes when requested to install dependencies

2. Configure HardHat

Update hardhat.config.ts to add the local network:

3. Counter Contract

HardHat created a contract for us! You can view the contract at contracts/Counter.sol:

4. Deploy the Contract

HardHat created a deployment script at ignition/modules/Counter.ts. Deploy the contract:

Example output:

5. Verify Deployment

In the console:

Create Substreams Module

1. Initialize Substreams Project

Follow the interactive prompts:

  • Chosen protocol: EVM

  • Chosen generator: evm-events-calls

  • Please enter the project name: counter

  • Please select the chain: Ethereum Mainnet (or the chain you are targeting)

  • Please enter the contract address: <CONTRACT_ADDRESS> (use your deployed address)

  • How do you want to provide the JSON ABI?: JSON in a local file

  • Input the full path of the JSON ABI: ./artifacts/contracts/Counter.sol/Counter.json

  • Please enter the contract initial block number: 0

  • Choose a short name for the contract: counter

  • What do you want to track for this contract?: Both events and calls

  • Is this contract a factory: No

  • Add another contract?: No

  • In which directory do you want to download the project?: ./substreams

  • How would you like to consume the Substreams?: To Postgres (or choose any other one)

The IDL file at ./artifacts/contracts/Counter.sol/Counter.json was automatically generated by Hardhat during the build process. We reference this file when initializing the Substreams module.

This will generate the basic Substreams module structure with the necessary configuration for tracking your Counter program.

2. Build and Test Substreams

Look for the deployment block as it's the one that will contain some actual data. You can scan a specific range using -s <DEPLOYMENT_BLOCK> -t +10 to scan 10 blocks starting from the deployment block.

You can also leave the substreams run running and open another terminal to run execute the Verify Deployment commands to see data being process live.

You should see the Increment events from your contract deployment!

Cleanup

Congratulations! You've completed the tutorial and have a working local HardHat development environment for Substreams.

When you're done, you can clean up the Docker environment with:

This will stop all containers and remove all data, allowing you to start fresh if needed.

Troubleshooting

For common issues with Docker Compose, RPC connectivity, Substreams, and platform-specific problems, see the Local Development Troubleshooting Guide.

Next Steps

Now that you have a working local environment:

  1. Try Other Platforms - Explore Foundry or Solana local development

  2. Advanced Substreams - Learn about modules, manifests, and data transformations

  3. Consuming Substreams - Connect to databases or streaming platforms

  4. Production Deployment - Move to production endpoints

Additional Resources

Last updated

Was this helpful?