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.
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. -
quasar- Written using Quasar, a zero-copy, zero-allocationno_stdframework for Solana programs with Anchor-compatible ergonomics. Build and test commands are the same as native examples. Runpnpm testto execute tests. -
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.
Hello World on Solana! A minimal program that logs a greeting.
Anchor Quasar Pinocchio Native
Store and retrieve data using Solana accounts.
Anchor Quasar Pinocchio Native
Use a PDA to store global state, making a counter that increments when called.
Anchor Quasar Pinocchio Native
Save and update per-user state on the blockchain, ensuring users can only update their own information.
Anchor Quasar Pinocchio Native
Check that the accounts provided in incoming instructions meet particular criteria.
Anchor Quasar Pinocchio Native
Close an account and get the Lamports back.
Anchor Quasar Pinocchio Native
Make new accounts on the blockchain.
Anchor Quasar Pinocchio Native
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.
Anchor Quasar Pinocchio Native
Add parameters to an instruction handler and use them.
Anchor Quasar Pinocchio Native
Store and retrieve state in Solana.
Anchor Quasar Pinocchio Native
How to store state that changes size in Solana.
Anchor Quasar Pinocchio Native
Determine the necessary minimum rent by calculating an account's size.
Anchor Quasar Pinocchio Native
Layout larger Solana onchain programs.
Send SOL between two accounts.
Anchor Quasar Pinocchio Native
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.
Create an NFT collection, mint NFTs, and verify NFTs as part of a collection using Metaplex Token Metadata.
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
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!
Create a fundraiser account specifying a target mint and amount, allowing contributors to deposit tokens until the goal is reached.
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.
Create liquidity pools to allow trading of new digital assets and allows users that provide liquidity to be rewarded by creating an Automated Market Maker.
Control token transfers using an external secp256k1 delegate signature.
Create token mints, mint tokens, and transfer tokens using Token Extensions.
Enable CPI guard to prevents certain token action from occurring within CPI (Cross-Program Invocation).
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.
Create tokens that store their onchain metadata inside the token mint, without needing to use or pay for additional programs.
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.
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.
Create tokens with an inbuilt transfer fee.
A minimal transfer hook program that executes custom logic on every token transfer.
Count how many times tokens have been transferred using a transfer hook.
Use token account owner data as seeds to derive extra accounts in a transfer hook.
Restrict or allow token transfers using an onchain allow/block list managed by a list authority.
Charge an additional cost or fee on every token transfer using a transfer hook.
Enable or disable token transfers with an onchain switch using a transfer hook.
Restrict token transfers so only whitelisted accounts can receive tokens.
Burn compressed NFTs.
Store Metaplex compressed NFTs inside a PDA.
Work with Metaplex compressed NFTs.
Use a data source for offchain data (called an Oracle) to perform activities onchain.
Use Shank and Solita to generate IDLs and TypeScript clients for native Solana programs, the same way Anchor does for Anchor programs.