Anchor
This guide walks you through setting up a complete local Solana development environment for Substreams development using Anchor. You'll deploy a sample Counter program, generate transactions, and stream the events using Substreams.
Estimated time: 20-25 minutes
What You'll Build
Local Solana validator (test mode)
Firehose integration for block streaming
Counter Anchor program with events
Substreams module to extract program 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
Anchor CLI (latest) - Installation guide
Solana CLI 2.x+ - Installation guide
Substreams CLI v1.7.0+ (installation guide)
Rust with
wasm32-unknown-unknowntargetcurl for testing endpoints
Architecture Overview
The local environment consists of:
Solana Validator (port 8899/8900) - Test validator with unlimited SOL
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 Program with Anchor
1. Install Required Tools
Anchor installation requires several prerequisites. Before proceeding, familiarize yourself with the Anchor installation requirements.
Install AVM (Anchor Version Manager):
Install and use the latest Anchor version:
Verify installation:
2. Configure Solana CLI
3. Initialize Anchor Project
4. Review Generated Program
The anchor init counter command created a basic program for us. The generated program source is located at programs/counter/src/lib.rs:
This simple program demonstrates the basic structure of an Anchor program with an initialize instruction.
5. Build and Deploy Program
Build the program:
Deploy to your local cluster (as configured in Anchor.toml):
After deployment, you'll see output similar to this:
Export the Program ID from the deployment output:
Replace <PROGRAM_ID> with the address from the Program Id: line (e.g., E2sTdp1aDaKbyh26BQkpYUH338u52fzwaiFbnym8MTk4) and <IDL_ACCOUNT> with the address from the Idl account created: line (e.g., G5GLdJwfDagZ7jfWjDZPBDwFNmZWtsY6WA3Lgbw6txmF).
8. Verify Deployment
Interact with the Counter Program
Now that the program is deployed, let's interact with it to generate some on-chain activity by calling the initialize instruction.
Start the Anchor shell:
In the Anchor shell, run the following commands to call the initialize instruction:
You should see a transaction signature returned, indicating the initialize instruction was successfully called.
Exit the shell:
This will create transactions on the local Solana validator that you can later observe when running your Substreams module.
Create Substreams Module
1. Initialize Substreams Project
Navigate back to the parent directory:
Initialize the Substreams module:
Follow the interactive prompts:
Chosen protocol:
SolanaChosen generator:
sol-anchor-betaPlease enter the project name:
counterPlease select the chain:
Solana Mainnet(or choose another chain)How do you want to provide the JSON IDL?:
JSON in a local fileInput the full path of your JSON IDL in your filesystem:
./counter/target/idl/counter.jsonDo you want to proceed with this IDL?:
YesAt what block do you want to start indexing data?:
0How would you like to consume the Substreams?:
To PostgresIn which directory do you want to download the project?:
./substreams
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 Counter program events from your deployment and interactions!
Cleanup
Congratulations! You've completed the tutorial and have a working local Anchor 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 Solana development 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?

