Solana Test Validator: A Comprehensive Guide for Developers

·

The Solana test validator is an essential tool for developers looking to build and test decentralized applications (dApps) before deploying them to the mainnet. It allows you to run a fully functional, single-node Solana cluster right on your local machine, providing unparalleled flexibility and control during the development process.

Why Use the Solana Test Validator?

Utilizing a local test environment offers numerous advantages over relying solely on public testnets or devnets. Here are some of the key benefits:

This level of customization makes the solana-test-validator indispensable for debugging, continuous integration (CI) pipelines, and ensuring your dApp behaves as expected under various network conditions.

Installing the Solana Test Validator

The solana-test-validator is included in the Solana Command Line Interface (CLI) tools suite. You must install the CLI tools on your development machine to get started.

Step-by-Step Installation Guide

  1. Visit the official Solana documentation for the most up-to-date installation instructions for your operating system (Linux, macOS, or Windows).
  2. Follow the steps to download and install the Solana CLI tools.
  3. Verify the installation was successful by opening a terminal and running:

    solana --version

    This command should return the current version of the installed Solana CLI, confirming you're ready to proceed.

Running and Configuring Your Local Validator

Once installed, starting your local test network is straightforward.

Initial Setup and Commands

First, it's good practice to familiarize yourself with all available configuration options. You can view the full list of commands by running:

solana-test-validator --help

To start the validator with its default configuration, simply execute:

solana-test-validator

The terminal will then display a live status output, providing real-time information about the state of your local blockchain.

Understanding the Status Output

When you run the validator, you'll see a status line similar to this:

Ledger location: test-ledger
Log: test-ledger/validator.log
Identity: EPhgPANa5Rh2wa4V2jxt7YbtWa3Uyw4sTeZ13cQjDDB8
Genesis Hash: 4754oPEMhAKy14CZc8GzQUP93CB4ouELyaTs4P8ittYn
Version: 1.6.7
Shred Version: 13286
Gossip Address: 127.0.0.1:1024
TPU Address: 127.0.0.1:1027
JSON RPC URL: http://127.0.0.1:8899
⠈ 00:36:02 | Processed Slot: 5142 | Confirmed Slot: 5142 | Finalized Slot: 5110 | Snapshot Slot: 5100 | Transactions: 5142 | ◎499.974295000

Keep the terminal window with the validator running. You can stop the process at any time by pressing Ctrl + C.

Interacting with Your Local Testnet

To interact with your running local validator, you need to open a new terminal window. You can use other Solana CLI tools or your own application code.

Configuring the CLI for Local Development

Direct the Solana CLI to communicate with your local testnet instead of a public cluster:

solana config set --url http://127.0.0.1:8899

Verify the configuration is correct by checking the genesis hash:

solana genesis-hash

The output should match the Genesis Hash: value displayed in your solana-test-validator status window.

Funding a Wallet and Making Transactions

  1. Check your wallet balance:

    solana balance

    If you see an error about a missing keypair file, you need to create a new wallet first using solana-keygen new.

  2. Airdrop SOL:
    If your balance is zero, request an airdrop:

    solana airdrop 10

    This will add 10 SOL to your default wallet.

  3. Perform a transfer:
    Test a basic transaction by sending SOL to another address (use the Identity pubkey from your validator status for testing):

    solana transfer <RECIPIENT_PUBKEY> 1

Monitoring Program Logs

To see the output of msg!() macros from your on-chain programs, use the log monitor in a separate terminal:

solana logs

Ensure this command is running before you execute a transaction you wish to monitor.

Advanced Configuration and Runtime Features

The test validator is highly configurable to suit different testing needs.

Managing Ledger Size and Location

The ledger data can grow large over time. To limit its size, use:

solana-test-validator --limit-ledger-size <NUMBER_OF_SLOTS>

To specify a custom directory for the ledger, use the --ledger flag.

Controlling Runtime Features

By default, the test validator runs with all runtime features activated. You can check the status of features with:

solana feature status --url localhost

However, for testing programs intended for mainnet deployment, you may want to deactivate specific features that are not yet live on the mainnet. This ensures your program is compatible.

solana-test-validator --deactivate-feature <FEATURE_PUBKEY_1> --deactivate-feature <FEATURE_PUBKEY_2>

👉 Explore more strategies for advanced local testing

Frequently Asked Questions

What is the Solana test validator used for?
The Solana test validator is a local single-node cluster that allows developers to test their smart contracts and dApps in a controlled environment. It provides features like unlimited airdrops, no rate limits, and the ability to clone state from mainnet, making it ideal for development and debugging before deploying to public networks.

How do I get SOL for my local testnet?
You can instantly airdrop SOL to any wallet on your local testnet using the command solana airdrop <AMOUNT>. There are no limits or waiting periods, unlike on public devnets or testnets.

Can I simulate mainnet conditions on the test validator?
Yes, you can closely simulate mainnet conditions. Use the --clone option to copy the state of specific accounts or programs from a public cluster. You can also deactivate certain runtime features to match the exact state of the mainnet chain at a given point in time.

My validator is using too much disk space. What can I do?
Use the --limit-ledger-size parameter when starting the validator to restrict how many slots of transaction history are stored. This significantly reduces disk usage while still allowing you to perform most development and testing tasks.

What is the RPC URL for the local test validator?
The default JSON-RPC URL for a locally running test validator is http://127.0.0.1:8899. You should configure your wallet, CLI tools, and application code to use this endpoint to interact with your local network.

How do I see logs from my on-chain programs?
Run solana logs in a separate terminal window. This stream will display all program output, including messages from msg!() macros, which is crucial for debugging the logic within your Solana programs.