Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A repository of Solana program examples

NotificationsYou must be signed in to change notification settings

solana-developers/program-examples

Repository files navigation

Onchain program examples for ⚓ Anchor 🦀 Native Rust, and [TS] TypeScript.

NativeAnchor

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 theSolana Developer site to learn more.

Each folder includes examples for one or more of the following:

  • anchor - Written usingAnchor, the most popular framework for Solana Development, which uses Rust. Useanchor build && anchor deploy to build & deploy the program. Runanchor run test to test it.
  • native - Written using Solana's native Rust crates and vanilla Rust. Usecicd.sh to build & deploy the program. Runyarn run test to test it.

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 thecontributing guidelines to keep things consistent.

The example programs

Basics

Hello world

Hello World on Solana! A minimal program that logs a greeting.

anchornative

Account-data

Store and retrieve data using Solana accounts.

anchornative

Storing global state - Counter

Use a PDA to store global state, making a counter that increments when called.

anchornative

Saving per-user state - Favorites

Save and update per-user state on the blockchain, ensuring users can only update their own information.

anchornative

Checking Instruction Accounts

Check that the accounts provided in incoming instructions meet particular criteria.

anchornative

Closing Accounts

Close an account and get the Lamports back.

anchornative

Creating Accounts

Make new accounts on the blockchain.

anchornative

Cross program invocations

Invoke an instruction handler from one onchain program in another onchain program.

anchornative

PDA rent-payer

Use a PDA to pay the rent for the creation of a new account.

anchornative

Processing instructions

Add parameters to an instruction handler and use them.

anchornative

Storing date in program derived addresses

Store and retrieve state in Solana.

anchornative

Handling accounts that expand in size

How to store state that changes size in Solana.

anchornative

Calculating account size to determine rent

Determine the necessary minimum rent by calculating an account's size.

anchornative

Laying out larger programs

Layout larger Solana onchain programs.

anchornative

Transferring SOL

Send SOL between two accounts.

anchornative

Tokens

Creating tokens

Create a token on Solana with a token symbol and icon.

anchornative

Minting NFTS

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.

anchornative

Minting a token from inside a program

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.

anchornative

Transferring Tokens

Transfer tokens between accounts

anchornative

Allowing users to swap digital assets - Escrow

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!

anchornative

Minting a token from inside a program with a PDA as the mint authority

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.

anchornative

Creating an Automated Market Maker

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.

anchor

Token Extensions

Basics - create token mints, mint tokens, and transfer tokens with Token Extensions

Create token mints, mint tokens, and transferr tokens using Token Extensions.

anchor

Preventing CPIs with CPI guard

Enable CPI guard to prevents certain token action from occurring within CPI (Cross-Program Invocation).

anchor

Using default account state

Create new token accounts that are frozen by default.

anchornative

Grouping tokens

Create tokens that belong to larger groups of tokens using the Group Pointer extension.

anchor

Creating token accounts whose owner cannot be changed

Create tokens whose owning program cannot be changed.

anchor

Interest bearing tokens

Create tokens that show an 'interest' calculation.

anchor

Requiring transactions to include descriptive memos

Create tokens where transfers must have a memo describing the transaction attached.

anchor

Adding on-chain metadata to the token mint

Create tokens that store their onchain metadata inside the token mint, without needing to use or pay for additional programs.

anchor

Allow a designedated account to close a mint

Allow a designated account to close a Mint.

anchornative

Usng multiple token extensions

Use multiple Token Extensions at once.

native

Non-transferrable - create tokens that can't be transferred.

Create tokens that cannot be transferred.

anchornative

Permanent Delegate - Create tokens permanently under the control of a particular account

Create tokens that remain under the control of an account, even when transferred elsewhere.

anchor

Create tokens with a transfer-fee.

Create tokens with an inbuilt transfer fee.

anchornative

Compression

Cnft-burn

Burn compressed NFTs.

anchor

Cnft-vault

Store Metaplex compressed NFTs inside a PDA.

anchor

Cutils

Work with Metaplex compressed NFTs.

anchor

Oracles

pyth

Use a data source for offchain data (called an Oracle) to perform activities onchain.

anchor



[8]ページ先頭

©2009-2025 Movatter.jp