Deploy
Deploy a Solana Program
Deploying a program on Solana involves writing your program in Rust, building it, and deploying it to the blockchain. Follow this guide for step-by-step instructions:
1. Install Prerequisites
Ensure you have the following tools installed on your system:
Rust: Install using rustup.
Solana CLI: Download from Solana's official docs.
Run the commands to confirm the installations:
2. Set Up the Solana CLI
Set the cluster to the Solana devnet or localnet:
Generate a new keypair if you donβt already have one:
Confirm the configuration:
3. Create a New Solana Program
Initialize a new Rust project:
Add dependencies: Update your
Cargo.toml
with the following dependencies:Write the program logic: Replace the contents of
src/lib.rs
with:
4. Build the Program
Build the program for the Solana BPF target:
This command outputs the .so
file (the compiled program) in the dist/program
directory.
5. Deploy the Program
Ensure you have some SOL for transaction fees. You can request airdrops:
Deploy the program using Solana CLI:
Note the program ID from the output.
6. Test the Program
Create a simple client to interact with your program.
Initialize a Rust client:
Add dependencies in
Cargo.toml
:Write client code in
src/main.rs
:
Run the client to verify interaction:
7. Clean Up
If using a local cluster, shut it down. For a remote cluster, make sure all test accounts are deactivated as needed.
Last updated