Skip to main content
Anchor is the leading development framework for building Solana programs (smart contracts) and simplifies the process of writing, testing, deploying, and interacting with Solana programs. The Anchor framework helps developers build production-ready applications faster while reducing potential vulnerabilities through built-in security features.

Why Anchor?

Anchor transforms Solana program development by providing powerful abstractions and safety guarantees that eliminate common security pitfalls and reduce boilerplate code.

Built-in security

Automatic account validation and security checks protect against common vulnerabilities

Less boilerplate

Rust macros eliminate repetitive code for account validation, serialization, and deserialization

Fast development

Built-in CLI tools for project scaffolding, building, testing, and deploying programs

TypeScript client

Auto-generated TypeScript clients from your program’s IDL for seamless frontend integration

Key features

Simplified program structure

Anchor uses Rust macros to reduce boilerplate and enforce best practices:
use anchor_lang::prelude::*;

declare_id!("YourProgramIDHere");

#[program]
pub mod my_program {
    use super::*;
    
    pub fn initialize(ctx: Context<Initialize>, data: u64) -> Result<()> {
        let account = &mut ctx.accounts.account;
        account.data = data;
        Ok(())
    }
}

#[derive(Accounts)]
pub struct Initialize<'info> {
    #[account(init, payer = user, space = 8 + 8)]
    pub account: Account<'info, MyAccount>,
    #[account(mut)]
    pub user: Signer<'info>,
    pub system_program: Program<'info, System>,
}

#[account]
pub struct MyAccount {
    pub data: u64,
}

Automatic account validation

Anchor’s account constraints provide compile-time and runtime validation:
  • Type safety: Account types ensure the correct program owns each account
  • Constraint validation: Built-in checks like init, mut, has_one, and constraint
  • Discriminators: Automatic 8-byte discriminators prevent account type confusion

IDL generation

Anchor automatically generates an Interface Description Language (IDL) file that describes your program’s public interface. This JSON file enables:
  • Auto-generated TypeScript clients
  • Easy program integration
  • Clear API documentation

Testing framework

Built-in testing support with TypeScript:
import * as anchor from "@anchor-lang/core";
import { Program } from "@anchor-lang/core";
import { MyProgram } from "../target/types/my_program";

describe("my-program", () => {
  const provider = anchor.AnchorProvider.env();
  anchor.setProvider(provider);

  const program = anchor.workspace.MyProgram as Program<MyProgram>;

  it("Initializes an account", async () => {
    const tx = await program.methods.initialize(new anchor.BN(42)).rpc();
    console.log("Transaction signature:", tx);
  });
});

Get started

Installation

Install Rust, Solana CLI, and Anchor CLI to set up your development environment

Quickstart

Build and deploy your first Anchor program in minutes

What you’ll build

In the quickstart guide, you’ll create a simple counter program that demonstrates:
  • Creating and initializing program accounts
  • Incrementing a counter value
  • Account validation with constraints
  • Testing with TypeScript
This foundational example will prepare you to build more complex Solana programs with Anchor.

Build docs developers (and LLMs) love