Building a Program with Pinocchio
A Pinocchio program combines a thin entrypoint, strict account validation, Borsh or opcode dispatch, and CPI helpers - mirroring native structure with less boilerplate overhead.
Recipe
entrypoint!(process_instruction);
fn process_instruction(id: &Pubkey, accounts: &[AccountInfo], data: &[u8]) -> ProgramResult {
match data.first() { Some(0) => init(id, accounts), _ => Err(ProgramError::InvalidInstructionData) }
}When to reach for this:
- Greenfield performance-sensitive program.
- Rewriting one Anchor instruction.
- Learning lightweight framework patterns.
Working Example
pub fn init(program_id: &Pubkey, accounts: &[AccountInfo]) -> ProgramResult {
let [payer, state, system @ ..] = accounts else { return Err(ProgramError::NotEnoughAccountKeys) };
if !payer.is_signer() { return Err(ProgramError::MissingRequiredSignature); }
// CPI create via pinocchio invoke / system instructions
Ok(())
}What this demonstrates:
- Fixed account slice destructuring.
- Signer verified first.
- System CPI for create follows validation.
Deep Dive
Module Layout
- entry.rs / lib.rs
- instructions/
- state.rs
- cpi.rs
IDL
Generate with Codama for @solana/kit 7.0.0 clients.
Rust Notes
// Centralize account validation helpers.Gotchas
- Skip validation - Worse than Anchor - no guardrails.. Fix: Copy native checklists.
- No IDL published - Clients break.. Fix: Codama pipeline.
- Mixed pinocchio/solana-program types - FFI confusion.. Fix: Pick one SDK surface per crate.
- Feature creep - Re-add Anchor-like macros.. Fix: Stay disciplined.
- No tests - CU regressions unnoticed.. Fix: LiteSVM CI.
Alternatives
| Alternative | Use When | Don't Use When |
|---|---|---|
| Anchor new project | Speed | CU |
| Steel framework | More sugar | Slightly heavier |
| Template repos | Bootstrap | Maintenance |
FAQs
Pinocchio + anchor in repo?
Separate programs via CPI.
Entrypoint alloc?
Configure per docs.
Token CPI?
Same spl helpers.
PDA sign?
invoke_signed equivalent.
Build command?
cargo build-sbf.
Verify?
solana-verify.
Deploy?
solana program deploy.
Upgrade?
Same loader as native.
Errors?
Custom u32 codes.
Logs?
Syscall log minimal.
Surfpool?
Local deploy test.
Agave 4.1.1?
Pin toolchain.
Related
- Pinocchio Basics - Intro
- Native Program Basics - Parallel concepts
- Interop & Migration - Moving stacks
Stack 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.