Program Examples

The Solana Program Examples repository on GitHub offers several subfolders, each containing code examples for different Solana programming paradigms and languages, designed to help developers learn and experiment with Solana blockchain development.

You can find the examples in the solana-developers/program-examples together with README files that explain you how to run the different examples. Most examples are self-contained and are available in native Rust (ie, with no framework) and Anchor. It also contains a list of examples that we would love to see as contributions.
Within the repo you will find the following subfolder, each with assorted example programs within them:

Basics #

Contains a series of examples that demonstrate the foundational steps for building Solana programs using native Rust libraries. These examples are designed to help developers understand the core concepts of Solana programming.

Example NameDescriptionLanguage
Account DataSaving an address with name, house number, street and city in an account.Native, Anchor
Checking AccountsSecurity lessons that shows how to do account checksNative, Anchor
Close AccountShow you how to close accounts to get its rent back.Native, Anchor
CounterA simple counter program in all the different architectures.Native, Anchor, mpl-stack
Create AccountHow to create a system account within a program.Native, Anchor
Cross Program InvocationUsing a hand and lever analogy this shows you how to call another program from within a program.Native, Anchor
hello solanaHello world example which just prints hello world in the transaction logs.Native, Anchor
Pda Rent payerShows you how you can use the lamports from a PDA to pay for a new account.Native, Anchor
Processing InstructionsShows you how to handle instruction data string and u32.Native, Anchor
Program Derived AddressesShows how to use seeds to refer to a PDA and save data in it.Native, Anchor
ReallocShows you how to increase and decrease the size of an existing account.Native, Anchor
RentHere you will learn how to calculate rent requirements within a program.Native, Anchor
Repository LayoutRecommendations on how to structure your program layout.Native, Anchor
Transfer SOLDifferent methods of transferring SOL for system accounts and PDAs.Native, Anchor, Seahorse

Compression #

Contains a series of examples that demonstrate how to use state compression on Solana. Mainly focused on compressed NFTs (cNFTs).

Example NameDescriptionLanguage
cNFT-burnTo destroy a cNFT it can be burnt. This examples shows how to do that in a program.Anchor
cNFT-VaultHow to custody a cNFT in a program and send it out again.Anchor
cutilsA suite utils to for example mint and verify cNFTs in a program.Anchor

Oracles #

Oracles allow to use off chain data in programs.

Example NameDescriptionLanguage
PythPyth makes price data of tokens available in on chain programs.Anchor

Tokens #

Most tokens on Solana use the Solana Program Library (SPL) token standard. Here you can find many examples on how to mint, transfer, burn tokens and even how to interact with them in programs.

Example NameDescriptionLanguage
Create TokenHow to create a token and add metaplex metadata to it.Anchor, Native
NFT MinterMinting only one amount of a token and then removing the mint authority.Anchor, Native
PDA Mint AuthorityShows you how to change the mint authority of a mint, to mint tokens from within a program.Anchor, Native
SPL Token MinterExplains how to use Associated Token Accounts to be able to keep track of token accounts.Anchor, Native
Token SwapExtensive example that shows you how to build a AMM (automated market maker) pool for SPL tokens.Anchor
Transfer TokensShows how to transfer SPL token using CPIs into the token program.Anchor, Native
Token-2022See Token 2022 (Token extensions).Anchor, Native

Token 2022 (Token Extensions) #

Token 2022 is a new standard for tokens on Solana. It is a more flexible and lets you add 16 different extensions to a token mint to add more functionality to it. A full list of the extensions can be found in the Getting Started Guide

Example NameDescriptionLanguage
BasicsHow to create a token, mint and transfer it.Anchor
Default account stateThis extension lets you create token accounts with a certain state, for example frozen.Native
Mint Close AuthorityWith the old token program it was not possible to close a mint. Now it is.Native
Multiple ExtensionsShows you how you can add multiple extensions to a single mintNative
NFT Metadata pointerIt is possible to use the metadata extension to create NFTs and add dynamic on chain metadata.Anchor
Not TransferableUseful for example for achievements, referral programs or any soul bound tokens.Native
Transfer feeEvery transfer of the tokens hold some tokens back in the token account which can then be collected.Native
Transfer HookFour examples to add additional functionality to your token using a CPI from the token program into your program.Anchor

Break #

Break is a React app that gives users a visceral feeling for just how fast and high-performance the Solana network really is. Can you break the Solana blockchain? During a 15 second play-through, each click of a button or keystroke sends a new transaction to the cluster. Smash the keyboard as fast as you can and watch your transactions get finalized in real-time while the network takes it all in stride!

Break can be played on our Devnet, Testnet and Mainnet Beta networks. Plays are free on Devnet and Testnet, where the session is funded by a network faucet. On Mainnet Beta, users pay to play 0.08 SOL per game. The session account can be funded by a local keystore wallet or by scanning a QR code from Trust Wallet to transfer the tokens.

Click here to play Break

Build and Run #

First fetch the latest version of the example code:

git clone https://github.com/solana-labs/break.git
cd break

Next, follow the steps in the git repository's README.