solana-anchor

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese
Skill based on Anchor (Solana program framework), generated from
sources/solana-anchor/docs/
at 2026-02-25.
Anchor is a Solana program framework: Rust eDSL with macros (
declare_id
,
#[program]
,
#[derive(Accounts)]
,
#[account]
), IDL generation, TypeScript/Rust clients, and CLI for build, test, and deploy. Use this skill when implementing or reviewing Anchor programs, CPIs, account validation, and client integration.
基于Anchor(Solana程序框架)的Skill,生成自
sources/solana-anchor/docs/
,生成时间2026-02-25。
Anchor是Solana的程序框架:带有宏的Rust领域特定语言(
declare_id
#[program]
#[derive(Accounts)]
#[account]
)、IDL生成、TypeScript/Rust客户端,以及用于构建、测试和部署的CLI。在实现或评审Anchor程序、CPI、账户验证和客户端集成时,可使用本Skill。

Core References

核心参考

TopicDescriptionReference
Program Structuredeclare_id, #[program], #[derive(Accounts)], #[account], Context, discriminatorscore-program-structure
CPICross-program invocation, CpiContext, PDA signers, invoke/invoke_signedcore-cpi
IDLInterface Description Language, instructions/accounts/discriminators, client usecore-idl
PDAProgram Derived Addresses, seeds, bump, seeds::program, init, IDL resolutioncore-pda
Workspaceinit, new, program layout, build/test/deploy flowcore-workspace
ReallocResize accounts, realloc::payer, realloc::zerocore-realloc
Close Accountclose = target, rent reclamationcore-close-account
Remaining Accountsctx.remaining_accounts, variadic instructions, CPIcore-remaining-accounts
主题描述参考
程序结构declare_id、#[program]、#[derive(Accounts)]、#[account]、Context、鉴别符core-program-structure
CPI跨程序调用、CpiContext、PDA签名者、invoke/invoke_signedcore-cpi
IDL接口描述语言、指令/账户/鉴别符、客户端使用core-idl
PDA程序派生地址、种子、bump、seeds::program、初始化、IDL解析core-pda
工作区初始化、新建、程序布局、构建/测试/部署流程core-workspace
重新分配调整账户大小、realloc::payer、realloc::zerocore-realloc
关闭账户close = target、租金回收core-close-account
剩余账户ctx.remaining_accounts、可变指令、CPIcore-remaining-accounts

References (Program & Config)

程序与配置参考

TopicDescriptionReference
Account TypesAccount, Signer, Program, AccountLoader, UncheckedAccount, etc.references-account-types
Account Constraintsinit, mut, seeds/bump, has_one, close, realloc, SPL, #[instruction]references-account-constraints
Anchor.tomlprovider, scripts, workspace, programs, test, toolchain, hooksreferences-anchor-toml
CLIbuild, deploy, test, idl, keys, migrate, upgrade, verifyreferences-cli
SpaceAccount size calculation, InitSpace, type sizesreferences-space
Type ConversionRust ↔ TypeScript type mapping for IDL/clientreferences-type-conversion
主题描述参考
账户类型Account、Signer、Program、AccountLoader、UncheckedAccount等references-account-types
账户约束init、mut、seeds/bump、has_one、close、realloc、SPL、#[instruction]references-account-constraints
Anchor.toml提供者、脚本、工作区、程序、测试、工具链、钩子references-anchor-toml
CLI构建、部署、测试、idl、密钥、迁移、升级、验证references-cli
空间账户大小计算、InitSpace、类型大小references-space
类型转换IDL/客户端的Rust ↔ TypeScript类型映射references-type-conversion

Features

功能特性

TopicDescriptionReference
Eventsemit!, emit_cpi!, addEventListener, decodingfeatures-events
Errors#[error_code], err!, require! and variantsfeatures-errors
Zero-CopyAccountLoader, load_init/load_mut/load, init vs zerofeatures-zero-copy
declare_program!IDL-based CPI and Rust client generationfeatures-declare-program
Tokens (SPL)anchor-spl, mints, token accounts, ATAs, Token 2022, InterfaceAccountfeatures-tokens
Token 2022 ExtensionsExtensionType, tlv_data, extension lifecycle, anchor-spl token_2022_extensionsfeatures-token-extensions
Example ProgramsCurated program-examples repo—Basics, Tokens, Token 2022—when to use eachfeatures-examples
TestingMollusk (Rust instruction harness), LiteSVM (Rust/TS/Python VM)features-testing
Upgrade and Migrateanchor upgrade, migrate script, upgrade authorityfeatures-upgrade-migrate
主题描述参考
事件emit!、emit_cpi!、addEventListener、解码features-events
错误#[error_code]、err!、require!及其变体features-errors
零拷贝AccountLoader、load_init/load_mut/load、init vs zerofeatures-zero-copy
declare_program!基于IDL的CPI和Rust客户端生成features-declare-program
代币(SPL)anchor-spl、铸币、代币账户、ATA、Token 2022、InterfaceAccountfeatures-tokens
Token 2022扩展ExtensionType、tlv_data、扩展生命周期、anchor-spl token_2022_extensionsfeatures-token-extensions
示例程序精选program-examples仓库——基础示例、代币示例、Token 2022示例——及各场景适用说明features-examples
测试Mollusk(Rust指令测试工具)、LiteSVM(Rust/TS/Python虚拟机)features-testing
升级与迁移anchor upgrade、迁移脚本、升级权限features-upgrade-migrate

Clients

客户端

TopicDescriptionReference
TypeScriptProgram, methods, accounts, signers, rpc/transaction/instruction, fetchclients-typescript
Rustanchor-client, declare_program!, request/instructions/send, account fetchclients-rust
主题描述参考
TypeScriptProgram、方法、账户、签名者、rpc/交易/指令、获取数据clients-typescript
Rustanchor-client、declare_program!、请求/指令/发送、账户数据获取clients-rust

Best Practices

最佳实践

TopicDescriptionReference
SecuritySealevel attacks, constraints, UncheckedAccount usagebest-practices-security
Constraints and ValidationWhen to use which constraints, avoid UncheckedAccount pitfallsbest-practices-constraints
主题描述参考
安全Sealevel攻击、约束条件、UncheckedAccount使用best-practices-security
约束与验证各类约束的适用场景、规避UncheckedAccount陷阱best-practices-constraints

Advanced

进阶内容

TopicDescriptionReference
Verifiable Buildsanchor build --verifiable, verify, Dockeradvanced-verifiable-builds
AVMAnchor Version Manager, install, use, listadvanced-avm
主题描述参考
可验证构建anchor build --verifiable、验证、Dockeradvanced-verifiable-builds
AVMAnchor版本管理器、安装、使用、列表查看advanced-avm