This repo contains Solana onchain programs (referred to as 'Smart Contracts' in other blockchains).
Program Examples
Snapshot 2026-08-03 23:56:39 UTC · version 1
Research document
Program Examples
Onchain program examples for ⚓ Anchor, 🤥 Pinocchio, and 🦀 Native Rust.
This repo contains Solana onchain programs (referred to as 'Smart Contracts' in other blockchains).
[!NOTE] If you're new to Solana, you don't need to create your own programs to perform basic things like making accounts, creating tokens, sending tokens, or minting NFTs. These common tasks are handled with existing programs, for example the System Program (for making account or transferring SOL) or the token program (for creating tokens and NFTs). See the Solana Developer site to learn more.
⚠️ This repository uses pnpm as the default package manager.
Ensure pnpm is installed before running any examples.
Each folder includes examples for one or more of the following:
anchor- Written using Anchor, the most popular framework for Solana development, which uses Rust. Useanchor buildandanchor deployto build and deploy the program. Tests should be executed usingpnpm testas defined in theAnchor.tomlscripts section.pinocchio- Written using Pinocchio, a zero-copy, zero-allocation library for Solana programs. Build and test commands are the same as native examples. Runpnpm testto execute tests.native- Written using Solana's native Rust crates and vanilla Rust. Build and test commands are defined via pnpm scripts and uselitesvmfor testing. Runpnpm testto execute tests.
If a given example is missing, please send us a PR to add it! Our aim is to have every example available in every option. We'd also love to see more programs involving staking, wrapped tokens, oracles, compression and VRF. Follow the contributing guidelines to keep things consistent.
The example programs
Basics
Hello world
Hello World on Solana! A minimal program that logs a greeting.
Account-data
Store and retrieve data using Solana accounts.
Storing global state - Counter
Store global state in an account, making a counter that increments when called.
Saving per-user state - Favorites
Save and update per-user state on the blockchain, ensuring users can only update their own information.
Checking Instruction Accounts
Check that the accounts provided in incoming instructions meet particular criteria.
Closing Accounts
Close an account and get the Lamports back.
Creating Accounts
Make new accounts on the blockchain, calculating the necessary minimum rent from the account's size.
Cross program invocations
Invoke an instruction handler from one onchain program in another onchain program.
PDA rent-payer
Use a PDA to pay the rent for the creation of a new account.
Processing instructions
Add parameters to an instruction handler and use them.
Storing date in program derived addresses
Store and retrieve state in Solana.
Handling accounts that expand in size
How to store state that changes size in Solana.
Laying out larger programs
Layout larger Solana onchain programs.
Transferring SOL
Send SOL between two accounts.
Tokens
Creating tokens
Create a token on Solana with a token symbol and icon.
NFT operations
Create an NFT collection, mint NFTs, and verify NFTs as part of a collection using Metaplex Token Metadata. Reminder: you don't need your own program just to mint an NFT, see the note at the top of this README.
Transferring Tokens
Create a token mint, mint tokens, and transfer tokens between accounts.
Allowing users to swap digital assets - Escrow
Allow two users to swap digital assets with each other, each getting 100% of what the other has offered due to the power of decentralization!
Fundraising with SPL Tokens
Create a fundraiser account specifying a target mint and amount, allowing contributors to deposit tokens until the goal is reached.
Distributing tokens with Merkle-proof claims
Fund a vault once, publish a Merkle root of a balance snapshot, and let each holder claim their allocation with a proof — the claim pattern behind large airdrops and chain migrations.
Minting a token from inside a program with a PDA as the mint authority
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.
Creating an Automated Market Maker
External delegate token master
Control token transfers using an external secp256k1 delegate signature.
Token Extensions
Basics - create token mints, mint tokens, and transfer tokens with Token Extensions
Create token mints, mint tokens, and transfer tokens using Token Extensions.
Preventing CPIs with CPI guard
Enable CPI guard to prevents certain token action from occurring within CPI (Cross-Program Invocation).
Using default account state
Create new token accounts that are frozen by default.
Grouping tokens
Create tokens that belong to larger groups of tokens using the Group Pointer extension.
Creating token accounts whose owner cannot be changed
Create tokens whose owning program cannot be changed.
Interest bearing tokens
Create tokens that show an 'interest' calculation.
Requiring transactions to include descriptive memos
Create tokens where transfers must have a memo describing the transaction attached.
Adding on-chain metadata to the token mint
Create tokens that store their onchain metadata inside the token mint, without needing to use or pay for additional programs.
Storing NFT metadata using the metadata pointer extension
Create an NFT using the Token Extensions metadata pointer, storing onchain metadata (including custom fields) inside the mint account itself.
Allow a designated account to close a mint
Allow a designated account to close a Mint.
Using multiple token extensions
Use multiple Token Extensions at once.
Non-transferrable - create tokens that can't be transferred.
Create tokens that cannot be transferred.
Permanent Delegate - Create tokens permanently under the control of a particular account
Create tokens that remain under the control of an account, even when transferred elsewhere.
Create tokens with a transfer-fee.
Create tokens with an inbuilt transfer fee.
Transfer hook - hello world
A minimal transfer hook program that executes custom logic on every token transfer.
Transfer hook - counter
Count how many times tokens have been transferred using a transfer hook.
Transfer hook - using account data as seed
Use token account owner data as seeds to derive extra accounts in a transfer hook.
Transfer hook - allow/block list
Restrict or allow token transfers using an on-chain allow/block list managed by a list authority.
Transfer hook - block list with Codama clients
A block-list transfer hook as a full project: Pinocchio program, Codama-generated Rust and TypeScript clients, and a CLI.
Transfer hook - transfer cost
Charge an additional cost or fee on every token transfer using a transfer hook.
Transfer hook - transfer switch
Enable or disable token transfers with an on-chain switch using a transfer hook.
Compression
Cnft-burn
Burn compressed NFTs.
Cnft-vault
Store Metaplex compressed NFTs inside a PDA.
Cutils
Work with Metaplex compressed NFTs.
Cryptography
One stateless program per curve, wrapping the raw cryptographic syscalls. These run in LiteSVM today but only work on public clusters once their feature gates activate. Applied examples (multisig, key registry, encrypted ballot) live in the crypto-primitives-examples reference repo.
BN254 (alt_bn128) operations
Add and scalar-multiply G2 points (SIMD-0302) and verify aggregate BLS signatures with a single pairing check, via the sol_alt_bn128_group_op syscall.
BLS12-381 curve operations
Add, subtract, and scalar-multiply BLS12-381 G1 and G2 points with the sol_curve_group_op syscall.
Oracles
pyth
Use a data source for offchain data (called an Oracle) to perform activities onchain.
Games
World Cup bracket prediction
A bracket-prediction game: entrants pay a fee to submit a 32-game bracket, an oracle posts results, scores are tallied on-chain, and the unique winner sweeps the pot. A full Pinocchio + Codama project with a TypeScript client and a webapp.
Why MDRSS assigned this score
- Production catalog audit 2026-08-04
- Taxonomy classified from title, annotation, source and Markdown signals
- Agent usefulness evaluated from structure, procedures, examples, evidence and retrieval value
Discussion 0
Sign in to join the discussion.