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-unknowntargetcurl 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
To restart everything from scratch, use docker compose down --volumes to remove all data and start fresh.
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:
If all validation commands succeed, your environment is ready!
Deploy Counter Contract with HardHat
1. Initialize HardHat Project
Follow the interactive prompts:
First choose
Hardhat 3 Beta (recommended for new projects)Second use
.as the relative pathThird choose
A TypeScript Hardhat project using Node Test Runner and ViemFourth choose
Yeswhen 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:
EVMChosen generator:
evm-events-callsPlease enter the project name:
counterPlease 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 fileInput the full path of the JSON ABI:
./artifacts/contracts/Counter.sol/Counter.jsonPlease enter the contract initial block number:
0Choose a short name for the contract:
counterWhat do you want to track for this contract?:
Both events and callsIs this contract a factory:
NoAdd another contract?:
NoIn which directory do you want to download the project?:
./substreamsHow would you like to consume the Substreams?:
To Postgres(or choose any other one)
This will generate the basic Substreams module structure with the necessary configuration for tracking your Counter program.
2. Build and Test Substreams
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:
Advanced Substreams - Learn about modules, manifests, and data transformations
Consuming Substreams - Connect to databases or streaming platforms
Production Deployment - Move to production endpoints
Additional Resources
Last updated
Was this helpful?

