Overview
Theanchor localnet command builds programs, starts a local Solana validator, deploys programs, and keeps the validator running for development and testing.
Command Syntax
Description
This command:- Builds all programs in the workspace (unless
--skip-build) - Starts a local validator (Surfpool or legacy)
- Deploys programs to the validator (unless
--skip-deploy) - Keeps the validator running until manually stopped
anchor test, the localnet command doesn’t run tests - it just provides a running local blockchain for manual testing and client development.
Options
Build Options
Skip building the program in the workspace
Skip checking for safety comments (“CHECK”) in the code
Skip checking for program ID mismatch between keypair and
declare_id!Architecture to use when building the programOptions:
sbf, bpfDeployment Options
Skip deploying programs (use previously deployed programs)
Validator Options
Validator type to use for local testingOptions:
surfpool: Use Surfpool validator (default, faster)legacy: Use Solana test validator
Advanced Options
Environment variables to pass into the Docker container
Arguments to pass to the underlying
cargo build-sbf command (use -- to separate)Examples
Basic Localnet
Start a local validator with automatic build and deployment:Skip Build
Start validator without rebuilding (faster when code hasn’t changed):Skip Deployment
Start fresh validator without deploying programs:Use Legacy Validator
Complete Skip (Restart Only)
Just restart the validator without build or deploy:Validator Details
Surfpool (Default)
Features:- Faster startup time (~2 seconds)
- Optimized for Anchor development
- Managed automatically
- Lower resource usage
http://localhost:8899
WebSocket: ws://localhost:8900
Legacy Validator
Features:- Standard
solana-test-validator - Full Solana CLI compatibility
- Advanced configuration options
- Suitable for complex testing
http://localhost:8899
WebSocket: ws://localhost:8900
Connecting to Localnet
Solana CLI
Configure the CLI to use localnet:Anchor Client (JavaScript/TypeScript)
Rust Client
Development Workflow
Interactive Development
Terminal 1: Run localnetCode Changes Workflow
- Make changes to program code
- Stop localnet (Ctrl+C)
- Restart with rebuild:
Managing the Validator
Start
Stop
PressCtrl+C in the terminal running localnet, or:
Reset State
Stop the validator and restart:Logs and Monitoring
View Logs
Monitor Transactions
Check Validator Status
Ledger Data
Validator state is stored in:- Account data
- Transaction history
- Validator configuration
Airdrop SOL
Get SOL for testing:Port Configuration
Default ports:- RPC: 8899
- WebSocket: 8900
anchor localnet directly.
Use Cases
Client Development
Manual Testing
Integration Testing
Comparison with anchor test
| Feature | anchor localnet | anchor test |
|---|---|---|
| Builds programs | ✓ | ✓ |
| Starts validator | ✓ | ✓ |
| Deploys programs | ✓ | ✓ |
| Runs tests | ✗ | ✓ |
| Keeps validator running | ✓ | ✗ (unless —detach) |
| Use case | Manual testing, client dev | Automated testing |
Notes
The validator runs in the foreground. Keep the terminal open or run it in a terminal multiplexer like
tmux or screen.For persistent local testing across sessions, consider preserving the
test-ledger/ or .surfpool/ directory.See Also
- anchor test - Run automated tests
- anchor build - Build programs
- anchor deploy - Deploy to any cluster
- anchor shell - Interactive shell for testing