Foundry
This guide walks you through setting up a complete local Ethereum development environment for Substreams development using Foundry. 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+
Foundry (forge, cast, anvil) - Installation guide
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 Foundry
1. Install Foundry
If you haven't installed Foundry yet:
2. Initialize Foundry Project
3. Configure Foundry
Add the following network configuration to foundry.toml (the file already exists from forge init):
4. Set Environment Variables
Set up the private key environment variable for easier command usage:
5. Use Default Counter Contract
Foundry already created a suitable Counter contract in src/Counter.sol. The default contract contains:
No need to modify this file - we'll use the default contract as-is.
6. Compile and Deploy
Example output:
Export the deployed contract address for easy reference:
Replace <DEPLOYED_ADDRESS> with the actual address from the deployment output (look for the Deployed to: field).
7. Verify Deployment
Test the deployed contract with the following sequence:
Expected output from the final call: 43 (42 + 1 from increment)
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: Use your deployed address (from
$CONTRACTvariable)How do you want to provide the JSON ABI?:
JSON in a local fileInput the full path of the JSON ABI:
./out/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 Foundry 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, and Substreams, 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?

