Create Solana programs with no dependencies attached.
I've got no dependencies
To hold me down
To make me fret
Or make me frown
I had dependencies
But now I'm free
There are no dependencies on me
Pinocchio is a zero-dependency library to create Solana programs in Rust. It takes advantage of the way SBF loaders serialize the program input parameters into a byte array that is then passed to the program's entrypoint to define zero-copy types to read the input. Since the communication between a program and SBF loader — either at the first time the program is called or when one program invokes the instructions of another program — is done via a byte array, a program can define its own types. This completely eliminates the dependency on the solana-program
crate, which in turn mitigates dependency issues by having a crate specifically designed to create on-chain programs.
Pinocchio can be used as a replacement for solana-program
to write on-chain programs.
The library defines:
- program entrypoint
- core data types
- logging macros
syscall
functions- access to system accounts (
sysvar
) - cross-program invocation
- Zero dependencies and
no_std
crate - Efficient
entrypoint!
macro – no copies or allocations - Improved CU consumption of cross-program invocations
From your project folder:
cargo add pinocchio
On your entrypoint definition:
use pinocchio::{
account_info::AccountInfo,
entrypoint,
entrypoint::ProgramResult,
msg,
pubkey::Pubkey
};
entrypoint!(process_instruction);
pub fn process_instruction(
program_id: &Pubkey,
accounts: &[AccountInfo],
instruction_data: &[u8],
) -> ProgramResult {
msg!("Hello from my program!");
Ok(())
}
⚠️ Note: You should use the types from thepinocchio
crate instead ofsolana-program
. If you need to invoke a different program, you will need to redefine its instruction builder to create an equivalent instruction data usingpinocchio
types.
The code is licensed under the Apache License Version 2.0
The library in this repository is based/includes code from: