This guide walks you through building, deploying, and calling a minimal
Solana on-chain program using Rust and Alchemy's Solana RPC.
If you're new to Solana development, this is the perfect first step to
validate your toolchain and RPC setup.
In this tutorial, you will:
- Install Solana + Rust tooling
- Scaffold a new Rust program
- Write a modern, minimal Solana program
- Build it to BPF
- Deploy to devnet
- Invoke it with a TypeScript client using Alchemy RPC
- View logs proving the program ran correctly
curl https://sh.rustup.rs -sSf | shcargo install solana-clinpm install -g pnpmFrom Alchemy dashboard → Create App → Solana → devnet.
mkdir solana-hello-world
cd solana-hello-world
cargo new --lib hello_worldOpen Cargo.toml and replace the contents with:
[package]
name = "hello_world"
version = "0.1.0"
edition = "2021"
[lib]
crate-type = ["cdylib"]
[dependencies]
solana-program = "1.18.0"Put this into src/lib.rs:
use solana_program::{
account_info::{next_account_info, AccountInfo},
entrypoint,
entrypoint::ProgramResult,
msg,
pubkey::Pubkey,
};
entrypoint!(process_instruction);
fn process_instruction(
_program_id: &Pubkey,
accounts: &[AccountInfo],
_instruction_data: &[u8],
) -> ProgramResult {
let accounts_iter = &mut accounts.iter();
let signer = next_account_info(accounts_iter)?;
msg!("👋 Hello, Solana from Alchemy!");
msg!("Invoked by signer: {}", signer.key);
Ok(())
}cargo build-sbfTo test this command was successful, run ls target/deploy - this should output something similar to:
hello_world.so
hello_world-keypair.jsonsolana-keygen newYou'll get:
Wrote new keypair to /Users/al/.config/solana/id.json
========================================================================
pubkey: 7QGE8McfeCHgm12Q8VN6jgBKqbbVdKpq5YiQrTyiMiNJ
========================================================================This wallet will pay for your deployments!
Use Alchemy:
solana config set --url https://solana-devnet.g.alchemy.com/v2/Pq8ZtHk2Gf3J4BH30ru_kYour terminal will output a confirmation message. ✅
solana airdrop 0.2Note: You may get a rate-limit error. If you do and need more devnet funds, try the official Solana faucet.
solana program deploy target/deploy/hello_world.soYour terminal will output something like:
Program Id: Eq5z52U3gGZNHVhgR1bgba8deMgtuFkpUNzd8iBsKvwJ
Signature: yhJxt2ovd3SzGRZbhTkWajkA3uvhX8iqLzuWSrPYyW6AAqZjD2Vq1ApxSAUS5ywQyUnwDwPG8vqKpJv1wgAUFwoimport {
Connection,
PublicKey,
Keypair,
Transaction,
TransactionInstruction,
} from "@solana/web3.js";
const ALCHEMY_RPC = "https://solana-devnet.g.alchemy.com/v2/YOUR_KEY";
const PROGRAM_ID = new PublicKey("YOUR_PROGRAM_ID");
async function main() {
const connection = new Connection(ALCHEMY_RPC);
const payer = Keypair.generate();
await connection.requestAirdrop(payer.publicKey, 1e9);
const ix = new TransactionInstruction({
programId: PROGRAM_ID,
keys: [{ pubkey: payer.publicKey, isSigner: true, isWritable: false }],
data: Buffer.alloc(0),
});
const tx = new Transaction().add(ix);
const sig = await connection.sendTransaction(tx, [payer]);
console.log("Transaction signature:", sig);
const logs = await connection.getTransaction(sig, {
commitment: "finalized",
});
console.log("Program logs:", logs?.meta?.logMessages);
}
main();You now have a working Solana program deployed on Solana devnet!
Check out the next guide on how to:
- set up a frontend for this program
- invoke it using Alchemy 🚀