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), Anchor,
Seahorse and 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 Name | Description | Language |
---|---|---|
Account Data | Saving an address with name, house number, street and city in an account. | Native, Anchor |
Checking Accounts | Security lessons that shows how to do account checks | Native, Anchor |
Close Account | Show you how to close accounts to get its rent back. | Native, Anchor |
Counter | A simple counter program in all the different architectures. | Native, Anchor, Seahorse, mpl-stack |
Create Account | How to create a system account within a program. | Native, Anchor |
Cross Program Invocation | Using a hand and lever analogy this shows you how to call another program from within a program. | Native, Anchor |
hello solana | Hello world example which just prints hello world in the transaction logs. | Native, Anchor |
Pda Rent payer | Shows you how you can use the lamports from a PDA to pay for a new account. | Native, Anchor |
Processing Instructions | Shows you how to handle instruction data string and u32. | Native, Anchor |
Program Derived Addresses | Shows how to use seeds to refer to a PDA and save data in it. | Native, Anchor |
Realloc | Shows you how to increase and decrease the size of an existing account. | Native, Anchor |
Rent | Here you will learn how to calculate rent requirements within a program. | Native, Anchor |
Repository Layout | Recommendations on how to structure your program layout. | Native, Anchor |
Transfer SOL | Different 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 Name | Description | Language |
---|---|---|
cNFT-burn | To destroy a cNFT it can be burnt. This examples shows how to do that in a program. | Anchor |
cNFT-Vault | How to custody a cNFT in a program and send it out again. | Anchor |
cutils | A suite utils to for example mint and verify cNFTs in a program. | Anchor |
Oracles #
Oracles allow to use off chain data in programs.
Example Name | Description | Language |
---|---|---|
Pyth | Pyth makes price data of tokens available in on chain programs. | Anchor, Seahorse |
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 Name | Description | Language |
---|---|---|
Create Token | How to create a token and add metaplex metadata to it. | Anchor, Native |
NFT Minter | Minting only one amount of a token and then removing the mint authority. | Anchor, Native |
PDA Mint Authority | Shows you how to change the mint authority of a mint, to mint tokens from within a program. | Anchor, Native |
SPL Token Minter | Explains how to use Associated Token Accounts to be able to keep track of token accounts. | Anchor, Native |
Token Swap | Extensive example that shows you how to build a AMM (automated market maker) pool for SPL tokens. | Anchor |
Transfer Tokens | Shows how to transfer SPL token using CPIs into the token program. | Anchor, Native, Seahorse |
Token-2022 | See 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 Name | Description | Language |
---|---|---|
Basics | How to create a token, mint and transfer it. | Anchor |
Default account state | This extension lets you create token accounts with a certain state, for example frozen. | Native |
Mint Close Authority | With the old token program it was not possible to close a mint. Now it is. | Native |
Multiple Extensions | Shows you how you can add multiple extensions to a single mint | Native |
NFT Metadata pointer | It is possible to use the metadata extension to create NFTs and add dynamic on chain metadata. | Anchor |
Not Transferable | Useful for example for achievements, referral programs or any soul bound tokens. | Native |
Transfer fee | Every transfer of the tokens hold some tokens back in the token account which can then be collected. | Native |
Transfer Hook | Four 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.
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.