Program Examples
The Solana Program Examples repository on GitHub offers several subfolders, each containing code examples 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.
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, 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 |
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 an 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 |
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. | Anchor, Native |
Mint Close Authority | With the old token program it was not possible to close a mint. Now it is. | Anchor, 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. | Anchor, Native |
Transfer fee | Every transfer of the tokens hold some tokens back in the token account which can then be collected. | Anchor, Native |
Transfer Hook | Four examples to add additional functionality to your token using a CPI from the token program into your program. | Anchor |
Is this page helpful?