Skip to main content

Overview

The anchor 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:
  1. Builds all programs in the workspace (unless --skip-build)
  2. Starts a local validator (Surfpool or legacy)
  3. Deploys programs to the validator (unless --skip-deploy)
  4. Keeps the validator running until manually stopped
Unlike 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

flag
default:"false"
Skip building the program in the workspace
flag
default:"false"
Skip checking for safety comments (“CHECK”) in the code
flag
default:"false"
Skip checking for program ID mismatch between keypair and declare_id!
enum
default:"sbf"
Architecture to use when building the programOptions: sbf, bpf

Deployment Options

flag
default:"false"
Skip deploying programs (use previously deployed programs)

Validator Options

enum
default:"surfpool"
Validator type to use for local testingOptions:
  • surfpool: Use Surfpool validator (default, faster)
  • legacy: Use Solana test validator

Advanced Options

array
Environment variables to pass into the Docker container
string
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:
Output:

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
RPC Endpoint: 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
RPC Endpoint: http://localhost:8899 WebSocket: ws://localhost:8900

Connecting to Localnet

Solana CLI

Configure the CLI to use localnet:
Verify connection:

Anchor Client (JavaScript/TypeScript)

Rust Client

Development Workflow

Interactive Development

Terminal 1: Run localnet
Terminal 2: Interact with programs
or run your client application:

Code Changes Workflow

  1. Make changes to program code
  2. Stop localnet (Ctrl+C)
  3. Restart with rebuild:
Or, if you want to rebuild and redeploy without restarting the validator:

Managing the Validator

Start

Stop

Press Ctrl+C in the terminal running localnet, or:

Reset State

Stop the validator and restart:
Or manually:

Logs and Monitoring

View Logs

Filter by program:

Monitor Transactions

Check Validator Status

Ledger Data

Validator state is stored in:
These directories contain:
  • Account data
  • Transaction history
  • Validator configuration

Airdrop SOL

Get SOL for testing:
or from Anchor:
or programmatically:

Port Configuration

Default ports:
  • RPC: 8899
  • WebSocket: 8900
These are typically configured in the validator and cannot be changed through anchor localnet directly.

Use Cases

Client Development

Manual Testing

Integration Testing

Comparison with anchor test

Notes

Use anchor localnet --skip-build when iterating on client code without changing programs to save time.
The validator runs in the foreground. Keep the terminal open or run it in a terminal multiplexer like tmux or screen.
Localnet data is ephemeral. When you stop the validator and restart, all account data is reset unless you preserve the ledger directory.
For persistent local testing across sessions, consider preserving the test-ledger/ or .surfpool/ directory.

See Also