Everything You Need to Know About Solana's Devnet
Written by Alchemy
Reviewed by Brady Werkheiser
Solana’s fast transaction speeds, low transaction costs, and developer-friendly environment make it an excellent chain for both dApp developers and users. If you're looking to start building on Solana, this article explains Solana's Devnet, an essential developer resource for testing smart contracts on a test network that mimics Solana's mainnet.
What is a cluster?
A cluster is a set of nodes which are responsible for evaluating the validity of incoming transactions to be added to the blockchain.
In each cluster one node is designated the ‘leader’ (the leader changes roughly every two days), which suggests which transactions should be added to the blockchain’s ledger and signs the suggested transactions with their signature. The other nodes within the cluster are ‘validators’, who double check whether the transactions are valid.
What is the Solana Devnet?
The Solana Devnet is an environment that replicates the actual Solana network (i.e. Mainnet) environment, but uses test SOL tokens to complete transactions so web3 developers don’t need to spend actual money to test their smart contracts.
The Solana Devnet is a safe playground for developers, users, and validators to test applications at no risk.
What is a Solana Devnet faucet?
To prevent network congestion from malicious actors while keeping the network free to use, the Solana Devnet uses a different token than mainnet.
Devnet tokens can be acquired either through the Solana Devnet faucet or from the following airdrop command you can enter in the Command Line Interface (CLI).
solana airdrop 2 --url https://api.devnet.solana.com
What is the Solana Devnet Explorer?
The Solana Devnet explorer allows web3 developers to search for any block, transaction, program, or token on the devnet. This tool helps developers get information about their transactions, debug transactions that aren’t working properly, and explore program details.
What is the difference between Solana’s testnet and devnet?
The difference between Solana’s Devnet and the Solana Testnet is that the testnet is a network meant to be used by Solana’s core developer team to test planned updates to the main network while Devnet is a testing environment for the general public to use.
How to Connect to Solana's Devnet
Before connecting to Solana's Devnet, it's important to make sure you install the essential Solana developer tools in your local environment. If you're starting from scratch, you can install the basic tools using the following instructions.
1. Install the Solana Tool Suite
First, will need the Solana Tool Suite to connect to the Devnet. How you install the tool suite will depend on whether or not you're running a MacOS, Linux, or Windows operating system. Here are instructions for each development environment.
Mac Users
If your operating system is MacOS or Linux, open your favorite terminal application and copy-paste the below command.
sh -c "$(curl -sSfL https://release.solana.com/v1.10.31/install)"
The version number can be replaced with any version which you wish to install
Windows Users
If Windows is your operating system, copy paste the below into Command Prompt instead.
curl https://release.solana.com/v1.10.31/solana-install-init-x86_64-pc-windows-msvc.exe --output C:\solana-install-tmp\solana-install-init.exe --create-dirs
Run this command to install the Tool Suite:
C:\solana-install-tmp\solana-install-init.exe v1.10.31
2. Check Your Version of Solana
Afterwards for all operating systems, run this to double check you have the desired version of Solana.
solana --version
3. Connect to the Devnet Cluster
Lastly, execute this command to connect to the Devnet cluster, and you will have connected to Devnet.
solana config set --url https://api.devnet.solana.com
How to Deploy a Solana Smart Contract to Devnet
In this tutorial we’re going to deploy the HelloWorld program that the Solana team developed. It creates a count for the account it is called on which represents the number of times that this program has been called on this account historically.
For example, the first execution will increase the count to 1 but return a count of 0. The second will return a count of 1 and increase it to 2.
Because we have already installed the Solana Tool Suite, we just need to install the following dependencies:
NodeJS
Rust
Git
Once the dependencies are installed, we'll clone the HelloWorld repo and follow the required steps to deploy it on Solana's Devnet.
1. Install NodeJS
To install NodeJS (you’ll need v14 or higher for this tutorial) - select the installer that matches your operating system.
After following the steps shown from running the installer NodeJS will automatically execute the node commands below in your terminal.
2. Install Rust
To install Rust, run this command if your operating system is MacOS, Linux, or other Unix-like operating systems, and your command line is ready.
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
On Windows, download and install rustup-init.exe.
3. Install Git
To install Git on Windows, select an installer to match your Windows version and follow the instructions.
To install Git on MacOS and Linux, first install Homebrew with the following command in your terminal of choice.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Then run the following command in the terminal to install Git with Homebrew.
$ brew install git
4. Clone the Solana HelloWorld Repo
With the dependencies installed, next, clone the HelloWorld repository in your environment.
git clone https://github.com/solana-labs/example-helloworldcd example-helloworld
5. Connect to Devnet
Double-check if you are connected to the Devnet cluster by running the following command.
solana config get
If you are not connected to the Devnet cluster, connect to the Devnet using this command:
solana config set --url https://api.devnet.solana.com
6. Generate a Keypair
Now, generate a keypair, which consists of a public key (your wallet address) and a private seed phrase. This keypair allows you to create an account on-chain and interact with Solana programs.
solana-keygen new --force
7. Get Devnet SOL Tokens
You’re going to need Devnet SOL tokens in order to run our program on the Devnet. You can request tokens through the following command.
solana airdrop 2 --url https://api.devnet.solana.com
8. Build and Deploy it to Devnet
Now, build the program and deploy it to Devnet.
npm run build:program-rust
At the bottom of the output that the console provides from building the program should be the command for deploying the program.
If you can’t find it, copy paste the command below to deploy the program to Solana’s Devnet.
solana program deploy dist/program/helloworld.so
Start Building on Solana
Using the Solana Devnet, web3 developers can build dApps on one of the highest performance layer 1 blockchains in the world. To start building, signup for access to Alchemy's Solana API.
Related overviews
Learn About Compressed NFTs and How They Work
Learn What an Associated Token Account Is, How it Works, and How to Create One
Learn What SFTs Are, How They Work, and What Makes Them Different from NFTs and SPL Tokens