Pinocchio Cookbook
Quick reference for Anchor developers switching to Pinocchio.
Anchor → Pinocchio
| Anchor |
Pinocchio |
#[program] |
entrypoint!(process_instruction) |
#[derive(Accounts)] |
Manual validation / TryFrom |
#[account] |
#[repr(C)] + zero-copy |
Context<T> |
(&Address, &[AccountView], &[u8]) |
Pubkey |
Address |
AccountInfo |
AccountView |
Cargo.toml
[package]
name = "my-program"
version = "0.1.0"
edition = "2021"
[lib]
crate-type = ["cdylib", "lib"]
[features]
bpf-entrypoint = []
cpi = ["pinocchio/cpi"]
[dependencies]
pinocchio = "0.10"
pinocchio-system = "0.3"
pinocchio-token = "0.4"
Minimal Program
#![no_std]
use pinocchio::{AccountView, Address, ProgramResult, entrypoint, error::ProgramError};
pub const ID: Address = pinocchio::address!("YourProgramId11111111111111111111111111111");
entrypoint!(process_instruction);
pub fn process_instruction(
program_id: &Address,
accounts: &[AccountView],
instruction_data: &[u8],
) -> ProgramResult {
let [account, ..] = accounts else {
return Err(ProgramError::NotEnoughAccountKeys);
};
// Your logic here
Ok(())
}
Build
cargo build-sbf
Docs
Examples
- Counter - Simple state with PDA
- Vault - Token custody with PDA signing