Pinocchio Basics
10 examples to get you started with Pinocchio - 7 basic and 3 intermediate.
Prerequisites
- Native program concepts from Native Program Basics.
- Rust 1.91.1 and Solana CLI 3.0.10.
Basic Examples
1. Add pinocchio dependency
Pinocchio replaces solana-program entry for minimal overhead.
[dependencies]
pinocchio = "0.8"- Check pinocchio release notes for Agave compatibility.
- Smaller dependency tree than full Anchor.
- Still
#![no_std]on-chain.
2. Entrypoint macro
Pinocchio provides entrypoint wiring.
use pinocchio::{account_info::AccountInfo, entrypoint, pubkey::Pubkey, ProgramResult};
entrypoint!(process_instruction);- Similar mental model to solana-program.
- Lower overhead invocation path.
- One entry per crate.
3. AccountInfo access
Read signer and writable flags.
if !account.is_signer() { return Err(ProgramError::MissingRequiredSignature); }- API mirrors native checks.
- You still validate everything manually.
- No auto constraints.
4. No std alloc
Optional allocator patterns.
#![no_std]
extern crate alloc;- Same alloc rules as native.
- Minimize heap use.
- Prefer account storage.
5. Pubkey type
Pinocchio pubkey types align with SDK bytes.
let key = account.key();- 32-byte keys.
- Compare for owner checks.
- PDA derivation off-chain or via syscall helpers.
6. Error returns
ProgramResult pattern unchanged.
return Err(ProgramError::InvalidArgument);- Custom errors map to u32.
- No Anchor error macro.
- Document codes for clients.
7. CPI with pinocchio
Invoke helpers with similar semantics.
pinocchio::program::invoke(&ix, &accounts)?;- invoke_signed for PDAs.
- Account meta ordering still callee-defined.
- See building program page.
Intermediate Examples
8. Instruction parsing
Manual or Borsh dispatch.
let (tag, rest) = data.split_at(1);
match tag[0] { 0 => init(rest), 1 => swap(rest), _ => Err(...) }- Opcode style saves bytes.
- Borsh still fine for complex payloads.
- Keep parser strict.
Related: Building a Program with Pinocchio
9. CU-conscious style
Avoid fmt and logs in hot paths.
// no msg in loop- Pinocchio wins eroded by logging.
- Profile with Surfpool.
- Compare against Anchor baseline.
Related: CU & Binary-Size Wins
10. Testing
LiteSVM 0.6.x runs pinocchio binaries.
// deploy .so in test fixture- Same integration patterns as native.
- Snapshot CU metrics.
- Fuzz instruction parser.
Related: LiteSVM
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.