> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/solana-foundation/anchor/llms.txt
> Use this file to discover all available pages before exploring further.

# Examples

> Explore example Anchor programs demonstrating various features and patterns

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

## Basic examples

<CardGroup cols={2}>
  <Card title="Basic-0" icon="rocket" href="https://github.com/solana-foundation/anchor/tree/master/tests/basic-0">
    Simple counter program with initialize and increment instructions
  </Card>

  <Card title="Basic-1" icon="database" href="https://github.com/solana-foundation/anchor/tree/master/tests/basic-1">
    Multiple accounts and data types
  </Card>

  <Card title="Basic-2" icon="user" href="https://github.com/solana-foundation/anchor/tree/master/tests/basic-2">
    Account validation and constraints
  </Card>

  <Card title="Basic-3" icon="shield" href="https://github.com/solana-foundation/anchor/tree/master/tests/basic-3">
    Authority checks and access control
  </Card>
</CardGroup>

## Intermediate examples

<CardGroup cols={2}>
  <Card title="Escrow" icon="handshake" href="https://github.com/solana-foundation/anchor/tree/master/tests/escrow">
    Token escrow with PDA vault
  </Card>

  <Card title="CPI" icon="arrows-turn-right" href="https://github.com/solana-foundation/anchor/tree/master/tests/cpi-returns">
    Cross-program invocations and return values
  </Card>

  <Card title="Events" icon="bell" href="https://github.com/solana-foundation/anchor/tree/master/tests/events">
    Emitting and listening to events
  </Card>

  <Card title="Errors" icon="circle-exclamation" href="https://github.com/solana-foundation/anchor/tree/master/tests/errors">
    Custom error handling
  </Card>
</CardGroup>

## Advanced examples

<CardGroup cols={2}>
  <Card title="Zero Copy" icon="bolt" href="https://github.com/solana-foundation/anchor/tree/master/tests/zero-copy">
    High-performance account deserialization
  </Card>

  <Card title="Declare Program" icon="file-code" href="https://github.com/solana-foundation/anchor/tree/master/tests/declare-program">
    Type-safe external program integration
  </Card>

  <Card title="IDL" icon="book" href="https://github.com/solana-foundation/anchor/tree/master/tests/idl">
    IDL generation and parsing
  </Card>

  <Card title="Custom Discriminator" icon="fingerprint" href="https://github.com/solana-foundation/anchor/tree/master/tests/custom-discriminator">
    Custom account and instruction discriminators
  </Card>
</CardGroup>

## Token programs

<CardGroup cols={2}>
  <Card title="Cashiers Check" icon="money-check" href="https://github.com/solana-foundation/anchor/tree/master/tests/cashiers-check">
    Token transfers with time locks
  </Card>

  <Card title="Lockup" icon="lock" href="https://github.com/solana-foundation/anchor/tree/master/tests/lockup">
    Vesting and token lockups
  </Card>
</CardGroup>

## Running examples

Clone the repository and run any example:

```bash theme={null}
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

<CardGroup cols={2}>
  <Card title="Browse all examples" icon="github" href="https://github.com/solana-foundation/anchor/tree/master/tests">
    View the complete list on GitHub
  </Card>

  <Card title="Quickstart tutorial" icon="play" href="/quickstart">
    Build your first program
  </Card>
</CardGroup>
