Esta página se muestra en inglés. Una traducción al español está en curso.
ConfigsJul 15, 2026·3 min de lectura

Anchor — Framework for Building Solana Programs in Rust

Anchor is the standard Rust framework for building Solana smart contracts (programs), providing account serialization, instruction dispatch, and client code generation to simplify Solana development.

Listo para agents

Instalación lista para agent

Este activo puede instalarse después de elegir el runtime, revisar el plan y ejecutar el comando correspondiente.

Native · 98/100Política: permitir
Superficie agent
Cualquier agent MCP/CLI
Tipo
Skill
Instalación
Single
Confianza
Confianza: Established
Entrada
Anchor
Comando de instalación directa
npx -y tokrepo@latest install ffaf6346-804b-11f1-9bc6-00163e2b0d79 --target codex

Ejecutar después de confirmar el plan con dry-run.

Introduction

Anchor is the dominant framework for building programs (smart contracts) on the Solana blockchain. It provides Rust macros and abstractions that handle account validation, serialization, and instruction routing, dramatically reducing the boilerplate needed for raw Solana development. Anchor also generates TypeScript client libraries and IDLs (Interface Definition Language) for each program.

What Anchor Does

  • Provides Rust procedural macros that generate account validation and deserialization boilerplate
  • Automatically creates IDL (Interface Definition Language) files describing program interfaces
  • Generates TypeScript client code from IDLs for frontend integration
  • Includes a testing framework with local validator support for integration tests
  • Manages program deployment and upgrades with built-in CLI tooling

Architecture Overview

An Anchor program is structured around three core macros: #[program] defines instruction handlers, #[derive(Accounts)] specifies account validation constraints, and #[account] defines serializable data structures. At compile time, these macros expand into the low-level Solana program code that validates accounts, checks constraints, and dispatches instructions. The IDL is extracted from the program's type information and published on-chain.

Self-Hosting & Configuration

  • Install the Anchor Version Manager (AVM) to manage framework versions across projects
  • Initialize projects with anchor init which scaffolds program, test, and client directories
  • Configure Anchor.toml for cluster endpoints, program IDs, and test validator settings
  • Build programs with anchor build which compiles the Rust code and generates IDL and TypeScript types
  • Run tests with anchor test which starts a local validator, deploys programs, and executes test scripts

Key Features

  • Declarative account validation with #[derive(Accounts)] and constraint attributes like #[account(mut, has_one = owner)]
  • Automatic IDL generation provides a machine-readable description of program instructions and accounts
  • Cross-Program Invocations (CPI) helpers simplify calling other Solana programs from Anchor code
  • Program Derived Addresses (PDA) are supported with seeds and bump constraints for deterministic account generation
  • Space calculation macros help determine the correct account size for rent-exempt allocations

Comparison with Similar Tools

  • Raw Solana SDK — lower-level with manual account parsing; Anchor provides higher-level abstractions and safety
  • Seahorse — Python-to-Solana compiler built on Anchor; simpler syntax but less control than native Anchor
  • Native Rust (solana-program) — maximum flexibility but requires manual serialization and validation
  • Shank — IDL generation for native programs; Anchor provides both IDL and the full development framework
  • Poseidon — TypeScript-to-Anchor transpiler for writing Solana programs in TS; Anchor uses Rust directly

FAQ

Q: Do I need to know Rust to use Anchor? A: Yes. Anchor programs are written in Rust. Familiarity with Rust ownership, traits, and macros helps significantly.

Q: What is an IDL in Anchor? A: An Interface Definition Language file that describes your program's instructions, accounts, and types. It enables automatic client generation and program verification.

Q: How does Anchor handle account validation? A: Through the #[derive(Accounts)] macro with constraint attributes. Anchor generates validation code that checks ownership, mutability, seeds, and custom conditions before instruction execution.

Q: Can I upgrade an Anchor program after deployment? A: Yes, programs deployed with upgrade authority can be redeployed. Use anchor upgrade or the Solana CLI to update the program binary.

Sources

Discusión

Inicia sesión para unirte a la discusión.
Aún no hay comentarios. Sé el primero en compartir tus ideas.

Activos relacionados