Anchor v2
Alpha docs for anchor-lang-v2, the pinocchio-based Anchor runtime.
Anchor is a framework for Solana programs. It provides a Rust eDSL for writing programs, an IDL format for describing them, generated client surfaces, and a CLI for the workspace loop.
anchor-lang-v2 is the alpha runtime for this version of Anchor. It is pinocchio-based, #![no_std], zero-copy by default for fixed-size accounts, and organized around traits so account wrappers, constraints, CPI helpers, and IDL metadata can be extended from downstream crates.
If you are new to Anchor, read the getting started pages first and keep the generated counter project open while reading the fundamentals. Most pages refer back to the same few pieces of the model, including a handler, a Context<T>, an accounts struct, account data, and generated client helpers.
Warning (Alpha)
This version is alpha software. It has not been audited, is not published on crates.io, and APIs
may break between commits. Depend on it from git on the
anchor-next branch.
Design#
Anchor programs are written as Rust handlers plus account validation structs. The runtime loads accounts, verifies constraints, derives PDAs, emits IDL metadata, and dispatches instructions into your handlers.
The default account model is fixed-size and zero-copy. Use Account<T> for Pod-backed account state, and use BorshAccount<T> when an account needs variable-length fields such as Vec or String. CPI uses borrow-tracked CpiHandle<'a> values so typed account access and cross-program calls share the same safety model.
Bench numbers#
Example (Bench programs)
You can see worked programs at
bench/programs/. Binary
sizes and CU ranges below are from the current Anchor programs on this branch.
Where to start#
Installation
Install the CLI from anchor-next and add git dependencies for anchor-lang-v2, anchor-spl-v2, and anchor-v2-testing.
First program
Scaffold a LiteSVM project and walk through the generated program, accounts, test, and profiling commands.
Migrating from v1
Port an existing v1 program with the rename table and account-model changes.
Account data model
Understand why Account<T> is zero-copy by default and when to use BorshAccount<T> instead.