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:
- No RPC Rate Limits: Execute an unlimited number of transactions and queries without hitting restrictive API limits.
- Unlimited Airdrops: Instantly fund your test wallets with SOL as needed, without waiting periods or restrictions.
- Direct Program Deployment: Easily deploy on-chain programs (BPF programs) using the
--bpf-programflag. - Clone Live Accounts: Simulate mainnet conditions by cloning accounts and programs from public clusters using the
--cloneoption. - Load Accounts from Files: Initialize your local ledger with specific account states from saved files.
- Configurable History: Control the size of the stored transaction history with the
--limit-ledger-sizeparameter to save disk space. - Custom Epoch Length: Adjust the number of slots per epoch using
--slots-per-epochfor testing staking and reward scenarios. - Time Travel: Fast-forward the blockchain to a specific slot using the
--warp-slotcommand for time-sensitive tests.
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
- Visit the official Solana documentation for the most up-to-date installation instructions for your operating system (Linux, macOS, or Windows).
- Follow the steps to download and install the Solana CLI tools.
Verify the installation was successful by opening a terminal and running:
solana --versionThis 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 --helpTo start the validator with its default configuration, simply execute:
solana-test-validatorThe 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- Ledger location: The file path where the blockchain data is stored.
- JSON RPC URL: This is the endpoint your applications will connect to (e.g.,
http://127.0.0.1:8899). - Processed/Confirmed/Finalized Slots: These show the progress of the blockchain through different confirmation levels.
- Vote Authority Balance: The amount of SOL in the validator's voting account.
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:8899Verify the configuration is correct by checking the genesis hash:
solana genesis-hashThe output should match the Genesis Hash: value displayed in your solana-test-validator status window.
Funding a Wallet and Making Transactions
Check your wallet balance:
solana balanceIf you see an error about a missing keypair file, you need to create a new wallet first using
solana-keygen new.Airdrop SOL:
If your balance is zero, request an airdrop:solana airdrop 10This will add 10 SOL to your default wallet.
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 logsEnsure 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 localhostHowever, 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.