Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Examples

The examples/ workspace members demonstrate practical usage patterns:

  • hello_solana: minimal program structure and instruction dispatch.
  • counter_program: PDA creation, mutation, and account validation.
  • todo_program: PDA-backed state with boolean + digest updates.
  • transfer_sol: lamport transfers and account checks.
  • escrow_program: richer multi-account flow and token-oriented logic.
  • vesting_program: token vesting / lockup scaffold with vault ATA setup and claim/cancel state.
  • role_registry_program: role-based configuration and registry PDAs with admin rotation.
  • staking_rewards_program: staking pool and user-position accounting scaffold with reward bookkeeping.
  • pina_bpf: minimal pina-native BPF hello world with nightly build-std=core,alloc.
  • anchor_declare_id: first Anchor test parity port, focused on program-id mismatch checks.
  • anchor_declare_program: Anchor declare-program parity for external-program ID checks.
  • anchor_duplicate_mutable_accounts: explicit duplicate mutable account validation pattern.
  • anchor_errors: Anchor-style custom error code and guard helper parity.
  • anchor_events: event schema parity through deterministic serialization checks.
  • anchor_floats: float data account create/update flow with authority validation.
  • anchor_system_accounts: system-program owner validation parity.
  • anchor_sysvars: clock/rent/stake-history sysvar validation parity.
  • anchor_realloc: realloc growth and duplicate-target safety checks.

Use examples as reference implementations for account layout, instruction parsing, and validation ordering.

Anchor test-suite parity progress is tracked in Anchor Test Porting.

Every example directory includes a local readme.md with purpose, coverage, and run commands.

When adding new examples:

  • Keep instruction/account discriminator handling explicit.
  • Use checked arithmetic in state transitions.
  • Include unit tests and clear doc comments for every instruction path.