Working, tested, up-to-date examples of common Solana programs - maintained by Quicknode
Solana Program Examples

Solana program examples ('smart contracts') in Anchor, Quasar, Pinocchio, native Rust, and sBPF assembly. Focused on financial software ('DeFi'), plus the basics, tokens, Token Extensions, state compression, and more.
Working, tested, up-to-date examples of common Solana programs (what other chains call smart contracts), maintained by Quicknode. Every example builds and passes CI on a current toolchain โ Anchor 1.1, the current multi-file program layout (one file per instruction handler, account type, etc), and LiteSVM tests rather than the older solana-test-validator / web3.js stack.
Each example is available in one or more of the following frameworks:
- โ Anchor - the most popular framework for Solana development. Build with
anchor build, test withanchor test. - ๐ซ Quasar - a newer, more performant framework with Anchor-compatible ergonomics. Build with
quasar build, test withquasar test. - ๐คฅ Pinocchio - a zero-copy, zero-allocation library for Solana programs. Build with
cargo build-sbf --manifest-path=./program/Cargo.toml, test withcargo test --manifest-path=./program/Cargo.toml. - ๐ฆ Native Rust - vanilla Rust using Solana's native crates. Build with
cargo build-sbf --manifest-path=./program/Cargo.toml, test withcargo test --manifest-path=./program/Cargo.toml. - ๐งฌ ASM - hand-written sBPF assembly built with the
sbpftoolchain. Build withsbpf build, test withcargo test.
[!NOTE]
You don't need to write your own program for basic tasks like creating accounts, transferring SOL, or minting tokens. These are handled by existing programs like the System Program and Token Program.
Getting started
You need Rust, Solana CLI, Anchor, and pnpm installed. Clone the repo and cd into any example directory, then run its tests with the command for that framework (shown above) - for an Anchor example, anchor test. pnpm is used for repo-wide formatting and linting, not for running an example's tests.
To deploy to mainnet or devnet you'll need an RPC endpoint. Quicknode provides free and paid Solana endpoints - create one and set it as your cluster in Anchor.toml or with solana config set --url <your-endpoint>.
Financial software ("DeFi")
The programs are examples of common financial primitives on Solana. As well as tests these all have formal verification using Kani. Every finance program ships with proofs that verify its money-math invariants exhaustively over all inputs. See each program's kani-proofs/ directory for the harnesses and what they prove.
Escrow
Start here - the best first finance program to learn on Solana. A neutral account that holds funds until both sides deliver, like a real-estate escrow or a lawyer's trust account. The maker deposits token A and names how much token B they want; when a taker supplies token B, the program swaps both in a single all-or-nothing transaction. This swap is the core idea behind every onchain exchange.
โ Anchor ๐ซ Quasar ๐ฆ Native
Lending
A borrow/lend market like Solend or Kamino: suppliers deposit a token and receive share tokens whose exchange rate rises as borrowers pay interest, borrowers post those shares as collateral to draw a different token against it up to a loan-to-value limit, and liquidators close part of any position that crosses its health threshold. Interest accrues through a utilization-based rate curve and a cumulative index, so no per-account accrual loop is needed.
Order Book based Exchange
A typical NYSE/NASDAQ-style order book-based exchange. Buyers post bids (the price they'll pay), sellers post asks (the price they'll accept), and a trade happens when a bid and an ask meet. The exchange operator collects fees from trading. Similar to popular Solana exchanges like Openbook and Phoenix.
AMM based Exchange
An exchange with no order book: swaps fill instantly against a shared liquidity pool funded by liquidity providers, who earn a cut of the trading fees. Prices are set algorithmically by the pool's balances. Anyone can create a pool, add or remove liquidity, and swap tokens, with slippage protection on every trade. Similar to Solana exchanges like Raydium and Orca.
Vault Strategy
A managed investment fund onchain, like an ETF or mutual fund. Investors deposit USDC for shares, a manager allocates the pool across a basket of assets (here, stocks like TSLAx and NVDAx), and each share's value tracks the fund's net asset value. The manager earns a management fee, and investors redeem a proportional slice of the underlying assets.
Betting Market
Parimutuel (pooled) prediction market - an admin opens an event with multiple outcomes, bettors stake tokens on an outcome, and at settlement the losing pool (minus a protocol fee) is split among winners in proportion to their stake.
Perpetual Futures
A perpetual futures exchange โ a venue for making leveraged bets on an asset's price without ever owning the asset. Traders post collateral and open a long (betting the price rises) or short (betting it falls) sized up to several times their collateral; their profit or loss tracks the price move and is paid in the collateral token. Rather than matching buyers to sellers, every trade is against a shared liquidity pool that other users fund and that is the counterparty to all of it โ the pool pays winners and keeps losers' collateral, and its providers earn the trading and funding fees in return. The price comes from an oracle, positions accrue a funding fee over time, and anyone can liquidate a position whose collateral can no longer cover its loss. This is the design behind venues like Jupiter Perpetuals and GMX.
Token Fundraiser
Onchain crowdfunding, like Kickstarter or GoFundMe. A creator sets a target amount in a chosen token, and contributors deposit into the fundraiser's account until the goal is reached.
Single concept examples
Hello Solana
A minimal program that logs a greeting.
โ Anchor ๐ซ Quasar ๐คฅ Pinocchio ๐ฆ Native ๐งฌ ASM
Account Data
Store and retrieve data using Solana accounts.
โ Anchor ๐ซ Quasar ๐คฅ Pinocchio ๐ฆ Native
Counter
Use a PDA to store global state - a counter that increments when called.
โ Anchor ๐ซ Quasar ๐คฅ Pinocchio ๐ฆ Native
Favorites
Save and update per-user state, ensuring users can only modify their own data.
โ Anchor ๐ซ Quasar ๐คฅ Pinocchio ๐ฆ Native
Checking Accounts
Validate that accounts provided in incoming instructions meet specific criteria.
โ Anchor ๐ซ Quasar ๐คฅ Pinocchio ๐ฆ Native ๐งฌ ASM
Close Account
Close an account and reclaim its lamports.
โ Anchor ๐ซ Quasar ๐คฅ Pinocchio ๐ฆ Native
Create Account
Create new accounts on the blockchain.
โ Anchor ๐ซ Quasar ๐คฅ Pinocchio ๐ฆ Native ๐งฌ ASM
Cross-Program Invocation
Call one program from another - the hand program invokes the lever program to toggle a switch.
โ Anchor ๐ซ Quasar ๐ฆ Native
PDA Rent Payer
Use a PDA to pay rent for creating a new account.
โ Anchor ๐ซ Quasar ๐คฅ Pinocchio ๐ฆ Native
Processing Instructions
Add parameters to an instruction handler and use them.
โ Anchor ๐ซ Quasar ๐คฅ Pinocchio ๐ฆ Native
Program Derived Addresses
Store and retrieve state using PDAs as deterministic account addresses.
โ Anchor ๐ซ Quasar ๐คฅ Pinocchio ๐ฆ Native
Realloc
Handle accounts that need to grow or shrink in size.
โ Anchor ๐ซ Quasar ๐คฅ Pinocchio ๐ฆ Native
Rent
Calculate an account's size to determine the minimum rent-exempt balance.
โ Anchor ๐ซ Quasar ๐คฅ Pinocchio ๐ฆ Native
Repository Layout
Structure a larger Solana program across multiple files and modules.
โ Anchor ๐ซ Quasar ๐ฆ Native
Transfer SOL
Send SOL between two accounts.
โ Anchor ๐ซ Quasar ๐คฅ Pinocchio ๐ฆ Native ๐งฌ ASM
Pyth Price Feeds
An oracle brings real-world market prices - a dollar, a stock, a token - onchain, like a Bloomberg terminal feeding live quotes. Pyth publishes low-latency prices from institutional sources, each in its own price feed account. This example reads a feed and logs its price, confidence interval, and exponent - the building block an AMM, lending market, or vault uses to value assets.
Tokens
Create Token
Create a token mint with a symbol and icon.
โ Anchor ๐ซ Quasar ๐ฆ Native
Mint NFT
Mint an NFT from inside your own program using the Token and Metaplex Token Metadata programs.
โ Anchor ๐ซ Quasar ๐ฆ Native
NFT Operations
Create an NFT collection, mint NFTs, and verify NFTs as part of a collection using Metaplex Token Metadata.
Token Minter
Mint tokens from inside your own program using the Classic Token Program.
โ Anchor ๐ซ Quasar ๐ฆ Native
Transfer Tokens
Transfer tokens between accounts.
โ Anchor ๐ซ Quasar ๐ฆ Native
PDA Mint Authority
Mint tokens using a PDA as the mint authority, so your program controls token issuance.
โ Anchor ๐ซ Quasar ๐ฆ Native
External Delegate Token Master
Control token transfers using an external secp256k1 delegate signature.
Token Extensions
Basics
Create token mints, mint tokens, and transfer tokens using Token Extensions.
CPI Guard
Prevent certain token actions from occurring within cross-program invocations.
Default Account State
Create new token accounts that are frozen by default.
โ Anchor ๐ซ Quasar ๐ฆ Native
Group Pointer
Create tokens that belong to larger groups using the Group Pointer extension.
Immutable Owner
Create token accounts whose owning program cannot be changed.
Interest Bearing Tokens
Create tokens that show an interest calculation, updating their displayed balance over time.
Memo Transfer
Require all transfers to include a descriptive memo.
Onchain Metadata
Store metadata directly inside the token mint account, without needing additional programs.
NFT Metadata Pointer
Create an NFT using the metadata pointer extension, storing onchain metadata (including custom fields) inside the mint.
Mint Close Authority
Allow a designated account to close a token mint.
โ Anchor ๐ซ Quasar ๐ฆ Native
Multiple Extensions
Use multiple Token Extensions on a single mint at once.
Non-Transferable Tokens
Create tokens that cannot be transferred between accounts.
โ Anchor ๐ซ Quasar ๐ฆ Native
Permanent Delegate
Create tokens that remain under the control of a designated account, even when transferred elsewhere.
Transfer Fee
Create tokens with a built-in transfer fee.
โ Anchor ๐ซ Quasar ๐ฆ Native
Transfer Hook - Hello World
A minimal transfer hook that executes custom logic on every token transfer.
Transfer Hook - Counter
Count how many times tokens have been transferred.
Transfer Hook - 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 onchain list managed by a list authority.
Transfer Hook - Transfer Cost
Charge an additional fee on every token transfer.
Transfer Hook - Transfer Switch
Enable or disable token transfers with an onchain switch.
Transfer Hook - Whitelist
Restrict transfers so only whitelisted accounts can receive tokens.
Compression
cNFT Burn
Burn compressed NFTs.
cNFT Vault
Store Metaplex compressed NFTs inside a PDA.
Compression Utilities
Work with Metaplex compressed NFTs.
Tools
Shank and Codama
Generate an IDL from a native Rust program with Shank, then generate a Rust client from that IDL with Codama.
Acknowledgements
Big thanks to Joe Caulfield and Solana Foundation for originally creating this repository.
PRs welcome! Follow the contributing guidelines and see CHANGELOG.md for release history.

