This repository contains examples demonstrating how to use Pinocchio, a zero-dependency library for creating Solana programs in Rust.
Pinocchio is a lightweight library that allows you to write Solana programs without depending on the solana-program crate. It leverages zero-copy types to read program input parameters directly from the byte array passed to the program's entrypoint by the SVM (Solana Virtual Machine) loader.
- Zero dependencies: Eliminates the need for
solana-programcrate - Resolves dependency conflicts: Avoids versioning issues with the Solana runtime
- Lightweight: Minimizes program size and complexity
- Efficient: Uses zero-copy deserialization for better performance
Basics
Hello World on Solana! A minimal program that logs a greeting.
Store and retrieve data using Solana accounts.
Use a PDA to store global state, making a counter that increments when called.
Check that the accounts provided in incoming instructions meet particular criteria.
Close an account and get the Lamports back.
Make new accounts on the blockchain.
Invoke an instruction handler from one onchain program in another onchain program.
Use a PDA to pay the rent for the creation of a new account.
Add parameters to an instruction handler and use them.
Store and retrieve state in Solana.
How to store state that changes size in Solana.
Determine the necessary minimum rent by calculating an account's size.
Tokens
Create a token on Solana with a token symbol and icon.
Mint an NFT from inside your own onchain program using the Token and Metaplex Token Metadata programs. Reminder: you don't need your own program just to mint an NFT, see the note at the top of this README.
Mint a Token from inside your own onchain program using the Token program. Reminder: you don't need your own program just to mint an NFT, see the note at the top of this README.
Transfer tokens between accounts
Mint a Token from inside your own onchain program using the Token program. Reminder: you don't need your own program just to mint an NFT, see the note at the top of this README.
Token Extensions
Create token mints, mint tokens, and transferr tokens using Token Extensions.
Create new token accounts that are frozen by default.
Create tokens that belong to larger groups of tokens using the Group Pointer extension.
Create tokens whose owning program cannot be changed.
Create tokens that show an 'interest' calculation.
Create tokens where transfers must have a memo describing the transaction attached.
Allow a designated account to close a Mint.
Use multiple Token Extensions at once.
Create tokens that cannot be transferred.
Create tokens that remain under the control of an account, even when transferred elsewhere.
Compression
- Rust and Cargo
- Solana CLI tools
- Basic knowledge of Solana program development
# Clone the repository
git clone https://github.com/yourusername/solana-pinocchio-examples.git
cd solana-pinocchio-examples
bun i
# Build the program
cargo build-sbf
# or
cargo-build-sbf
# Run tests
cargo test
# or
cargo test -p example_program
# Test on devnet
# Get program ID
solana address -k target/deploy/example_program-keypair.json
# Deploy
solana program deploy target/deploy/example_program.so --program-id ./target/deploy/example_program-keypair.json
# Make sure you have update program ID in the codama node struct for generate client code
bun gen:client:example_program
bun test:client:example_program
To create a new Pinocchio program you need install Rust and the Solana CLI tools. Then you can use the following steps:
-
Create a new Rust library project:
cargo new --lib my_pinocchio_program --edition 2021
cd my_pinocchio_program
-
Install the Pinocchio crate:
cargo add pinocchio
That is all you need to do to set up a new Pinocchio program. Let start coding!
The typical directory structure for a Pinocchio program inspired by the Anchor framework looks like this:
my_pinocchio_program/
├── Cargo.toml
├── src/
│ ├── lib.rs
│ ├── instructions/
| | └── mod.rs
│ ├── state/
| | └── mod.rs
│ ├── error.rs
| ├── constants.rs
| └── util.rs
├── tests/
│ └── integration_tests.rs
└── target/
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.