Skip to content

Latest commit

 

History

History
329 lines (167 loc) · 13.3 KB

File metadata and controls

329 lines (167 loc) · 13.3 KB

Quicknode Solana Program Examples

A fork of the Solana Foundation program examples with current versions, more programs, and additional frameworks.

Anchor Quasar Pinocchio Native

Each example is available in one or more of the following frameworks:

  • ⚓ Anchor — the most popular framework for Solana development. Build with anchor build, test with pnpm test as defined in Anchor.toml.
  • 💫 Quasar — a newer, more performant framework with Anchor-compatible ergonomics. Run pnpm test to execute tests.
  • 🤥 Pinocchio — a zero-copy, zero-allocation library for Solana programs. Run pnpm test to execute tests.
  • 🦀 Native Rust — vanilla Rust using Solana's native crates. Run pnpm test to execute tests.

Note

You don't need to write your own program for basic tasks like creating accounts, transferring SOL, or minting tokens. These are handled by existing programs like the System Program and Token Program.

Financial Software

Automated Market Maker

Constant product AMM (x·y=k) — create liquidity pools, deposit and withdraw liquidity, swap tokens with fees and slippage protection.

⚓ Anchor 💫 Quasar

Escrow

Peer-to-peer OTC trade — one user deposits token A and specifies how much token B they want. A counterparty fulfils the offer and both sides receive their tokens atomically.

⚓ Anchor 💫 Quasar 🦀 Native

Token Fundraiser

Create a fundraiser specifying a target mint and amount. Contributors deposit tokens until the goal is reached.

⚓ Anchor 💫 Quasar

Pyth Price Feeds

Read offchain price data onchain using the Pyth oracle network.

⚓ Anchor 💫 Quasar

Basics

Hello Solana

A minimal program that logs a greeting.

⚓ Anchor 💫 Quasar 🤥 Pinocchio 🦀 Native

Account Data

Store and retrieve data using Solana accounts.

⚓ Anchor 💫 Quasar 🤥 Pinocchio 🦀 Native

Counter

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

⚓ Anchor 💫 Quasar 🤥 Pinocchio 🦀 Native

Favorites

Save and update per-user state, ensuring users can only modify their own data.

⚓ Anchor 💫 Quasar 🤥 Pinocchio 🦀 Native

Checking Accounts

Validate that accounts provided in incoming instructions meet specific criteria.

⚓ Anchor 💫 Quasar 🤥 Pinocchio 🦀 Native

Close Account

Close an account and reclaim its lamports.

⚓ Anchor 💫 Quasar 🤥 Pinocchio 🦀 Native

Create Account

Create new accounts on the blockchain.

⚓ Anchor 💫 Quasar 🤥 Pinocchio 🦀 Native

Cross-Program Invocation

Call one program from another — the hand program invokes the lever program to toggle a switch.

⚓ Anchor 💫 Quasar 🦀 Native

PDA Rent Payer

Use a PDA to pay rent for creating a new account.

⚓ Anchor 💫 Quasar 🤥 Pinocchio 🦀 Native

Processing Instructions

Add parameters to an instruction handler and use them.

⚓ Anchor 💫 Quasar 🤥 Pinocchio 🦀 Native

Program Derived Addresses

Store and retrieve state using PDAs as deterministic account addresses.

⚓ Anchor 💫 Quasar 🤥 Pinocchio 🦀 Native

Realloc

Handle accounts that need to grow or shrink in size.

⚓ Anchor 💫 Quasar 🤥 Pinocchio 🦀 Native

Rent

Calculate an account's size to determine the minimum rent-exempt balance.

⚓ Anchor 💫 Quasar 🤥 Pinocchio 🦀 Native

Repository Layout

Structure a larger Solana program across multiple files and modules.

⚓ Anchor 💫 Quasar 🦀 Native

Transfer SOL

Send SOL between two accounts.

⚓ Anchor 💫 Quasar 🤥 Pinocchio 🦀 Native

Tokens

Create Token

Create a token mint with a symbol and icon.

⚓ Anchor 💫 Quasar 🦀 Native

Mint NFT

Mint an NFT from inside your own program using the Token and Metaplex Token Metadata programs.

⚓ Anchor 💫 Quasar 🦀 Native

NFT Operations

Create an NFT collection, mint NFTs, and verify NFTs as part of a collection using Metaplex Token Metadata.

⚓ Anchor 💫 Quasar

SPL Token Minter

Mint tokens from inside your own program using the Token program.

⚓ Anchor 💫 Quasar 🦀 Native

Transfer Tokens

Transfer tokens between accounts.

⚓ Anchor 💫 Quasar 🦀 Native

PDA Mint Authority

Mint tokens using a PDA as the mint authority, so your program controls token issuance.

⚓ Anchor 💫 Quasar 🦀 Native

External Delegate Token Master

Control token transfers using an external secp256k1 delegate signature.

⚓ Anchor 💫 Quasar

Token Extensions

Basics

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

⚓ Anchor 💫 Quasar

CPI Guard

Prevent certain token actions from occurring within cross-program invocations.

⚓ Anchor 💫 Quasar

Default Account State

Create new token accounts that are frozen by default.

⚓ Anchor 💫 Quasar 🦀 Native

Group Pointer

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

⚓ Anchor 💫 Quasar

Immutable Owner

Create token accounts whose owning program cannot be changed.

⚓ Anchor 💫 Quasar

Interest Bearing Tokens

Create tokens that show an interest calculation, updating their displayed balance over time.

⚓ Anchor 💫 Quasar

Memo Transfer

Require all transfers to include a descriptive memo.

⚓ Anchor 💫 Quasar

Onchain Metadata

Store metadata directly inside the token mint account, without needing additional programs.

⚓ Anchor

NFT Metadata Pointer

Create an NFT using the metadata pointer extension, storing onchain metadata (including custom fields) inside the mint.

⚓ Anchor

Mint Close Authority

Allow a designated account to close a token mint.

⚓ Anchor 💫 Quasar 🦀 Native

Multiple Extensions

Use multiple Token Extensions on a single mint at once.

🦀 Native

Non-Transferable Tokens

Create tokens that cannot be transferred between accounts.

⚓ Anchor 💫 Quasar 🦀 Native

Permanent Delegate

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

⚓ Anchor 💫 Quasar

Transfer Fee

Create tokens with a built-in transfer fee.

⚓ Anchor 💫 Quasar 🦀 Native

Transfer Hook — Hello World

A minimal transfer hook that executes custom logic on every token transfer.

⚓ Anchor 💫 Quasar

Transfer Hook — Counter

Count how many times tokens have been transferred.

⚓ Anchor 💫 Quasar

Transfer Hook — Account Data as Seed

Use token account owner data as seeds to derive extra accounts in a transfer hook.

⚓ Anchor 💫 Quasar

Transfer Hook — Allow/Block List

Restrict or allow token transfers using an onchain list managed by a list authority.

⚓ Anchor 💫 Quasar

Transfer Hook — Transfer Cost

Charge an additional fee on every token transfer.

⚓ Anchor 💫 Quasar

Transfer Hook — Transfer Switch

Enable or disable token transfers with an onchain switch.

⚓ Anchor 💫 Quasar

Transfer Hook — Whitelist

Restrict transfers so only whitelisted accounts can receive tokens.

⚓ Anchor 💫 Quasar

Compression

cNFT Burn

Burn compressed NFTs.

⚓ Anchor 💫 Quasar

cNFT Vault

Store Metaplex compressed NFTs inside a PDA.

⚓ Anchor 💫 Quasar

Compression Utilities

Work with Metaplex compressed NFTs.

⚓ Anchor 💫 Quasar


PRs welcome! Follow the contributing guidelines to keep things consistent.