Skip to main content
Learn Anchor through practical examples. The Anchor repository contains numerous example programs demonstrating different features and patterns.

Basic examples

Basic-0

Simple counter program with initialize and increment instructions

Basic-1

Multiple accounts and data types

Basic-2

Account validation and constraints

Basic-3

Authority checks and access control

Intermediate examples

Escrow

Token escrow with PDA vault

CPI

Cross-program invocations and return values

Events

Emitting and listening to events

Errors

Custom error handling

Advanced examples

Zero Copy

High-performance account deserialization

Declare Program

Type-safe external program integration

IDL

IDL generation and parsing

Custom Discriminator

Custom account and instruction discriminators

Token programs

Cashiers Check

Token transfers with time locks

Lockup

Vesting and token lockups

Running examples

Clone the repository and run any example:
git clone https://github.com/solana-foundation/anchor
cd anchor/tests/<example-name>
anchor test

Example structure

Each example typically includes:
  • programs/: The Rust program code
  • tests/: TypeScript tests demonstrating usage
  • Anchor.toml: Project configuration

Learn more

Browse all examples

View the complete list on GitHub

Quickstart tutorial

Build your first program

Build docs developers (and LLMs) love