Programs Basics
9 examples to get you started with Solana programs on the Sealevel runtime - 6 basic and 3 intermediate.
Search across all documentation pages
9 examples to get you started with Solana programs on the Sealevel runtime - 6 basic and 3 intermediate.
cargo install --git https://github.com/coral-xyz/anchor --tag v0.32.1 anchor-cli
anchor --versionuse anchor_lang::prelude::*;
declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");
#[program]
pub mod hello {
use super::*;
pub fn initialize(_ctx: Context<Initialize>) -> Result<()> {
msg!("Hello from Agave 4.1.1");
Ok(())
}
}
#[derive(Accounts)]
pub struct Initialize {}#[program] generates the instruction dispatcher and entrypointRelated: The Program Entrypoint
anchor build
anchor deploy --provider.cluster devnet
solana program show <PROGRAM_ID>declare_id! keypairRelated: Program Loaders & Upgradeability
anchor run test
# Or: solana program invoke <PROGRAM_ID> --data <BYTES>#[account]
pub struct Counter { pub value: u64 }
// State in Counter account, not in program binaryRelated: Stateless Programs
#[derive(Accounts)]
pub struct Increment<'info> {
#[account(mut)]
pub counter: Account<'info, Counter>,
}solana confirm -v <SIG> | grep "consumed"Related: Compute Units & Budgets
use anchor_lang::system_program;
pub fn fund(ctx: Context<Fund>, lamports: u64) -> Result<()> {
system_program::transfer(
CpiContext::new(ctx.accounts.system_program.to_account_info(), /* ... */),
lamports,
)?;
Ok(())
}#[account(seeds = [b"user", user.key().as_ref()], bump)]
pub position: Account<'info, Position>,Related: Sealevel Parallel Execution
npx surfpool@0.12.0 run anchor testStack versions: This page was written for Agave 4.1.1, Solana CLI 3.0.10, Anchor 0.32.1, anchor-lang 0.32.1, Rust 1.91.1, @solana/kit 7.0.0, Surfpool 0.12.0, and LiteSVM 0.6.x.
Reviewed by Chris St. John·Last updated Jul 16, 2026