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 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

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 an 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.Anchor, Native
Mint Close AuthorityWith the old token program it was not possible to close a mint. Now it is.Anchor, 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.Anchor, Native
Transfer feeEvery transfer of the tokens hold some tokens back in the token account which can then be collected.Anchor, Native
Transfer HookFour examples to add additional functionality to your token using a CPI from the token program into your program.Anchor

Is this page helpful?

Table of Contents

Edit Page