solana-anchor
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSkill based on Anchor (Solana program framework), generated fromat 2026-02-25.sources/solana-anchor/docs/
Anchor is a Solana program framework: Rust eDSL with macros (, , , ), 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.
declare_id#[program]#[derive(Accounts)]#[account]基于Anchor(Solana程序框架)的Skill,生成自,生成时间2026-02-25。sources/solana-anchor/docs/
Anchor是Solana的程序框架:带有宏的Rust领域特定语言(、、、)、IDL生成、TypeScript/Rust客户端,以及用于构建、测试和部署的CLI。在实现或评审Anchor程序、CPI、账户验证和客户端集成时,可使用本Skill。
declare_id#[program]#[derive(Accounts)]#[account]Core References
核心参考
| Topic | Description | Reference |
|---|---|---|
| Program Structure | declare_id, #[program], #[derive(Accounts)], #[account], Context, discriminators | core-program-structure |
| CPI | Cross-program invocation, CpiContext, PDA signers, invoke/invoke_signed | core-cpi |
| IDL | Interface Description Language, instructions/accounts/discriminators, client use | core-idl |
| PDA | Program Derived Addresses, seeds, bump, seeds::program, init, IDL resolution | core-pda |
| Workspace | init, new, program layout, build/test/deploy flow | core-workspace |
| Realloc | Resize accounts, realloc::payer, realloc::zero | core-realloc |
| Close Account | close = target, rent reclamation | core-close-account |
| Remaining Accounts | ctx.remaining_accounts, variadic instructions, CPI | core-remaining-accounts |
| 主题 | 描述 | 参考 |
|---|---|---|
| 程序结构 | declare_id、#[program]、#[derive(Accounts)]、#[account]、Context、鉴别符 | core-program-structure |
| CPI | 跨程序调用、CpiContext、PDA签名者、invoke/invoke_signed | core-cpi |
| IDL | 接口描述语言、指令/账户/鉴别符、客户端使用 | core-idl |
| PDA | 程序派生地址、种子、bump、seeds::program、初始化、IDL解析 | core-pda |
| 工作区 | 初始化、新建、程序布局、构建/测试/部署流程 | core-workspace |
| 重新分配 | 调整账户大小、realloc::payer、realloc::zero | core-realloc |
| 关闭账户 | close = target、租金回收 | core-close-account |
| 剩余账户 | ctx.remaining_accounts、可变指令、CPI | core-remaining-accounts |
References (Program & Config)
程序与配置参考
| Topic | Description | Reference |
|---|---|---|
| Account Types | Account, Signer, Program, AccountLoader, UncheckedAccount, etc. | references-account-types |
| Account Constraints | init, mut, seeds/bump, has_one, close, realloc, SPL, #[instruction] | references-account-constraints |
| Anchor.toml | provider, scripts, workspace, programs, test, toolchain, hooks | references-anchor-toml |
| CLI | build, deploy, test, idl, keys, migrate, upgrade, verify | references-cli |
| Space | Account size calculation, InitSpace, type sizes | references-space |
| Type Conversion | Rust ↔ TypeScript type mapping for IDL/client | references-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
功能特性
| Topic | Description | Reference |
|---|---|---|
| Events | emit!, emit_cpi!, addEventListener, decoding | features-events |
| Errors | #[error_code], err!, require! and variants | features-errors |
| Zero-Copy | AccountLoader, load_init/load_mut/load, init vs zero | features-zero-copy |
| declare_program! | IDL-based CPI and Rust client generation | features-declare-program |
| Tokens (SPL) | anchor-spl, mints, token accounts, ATAs, Token 2022, InterfaceAccount | features-tokens |
| Token 2022 Extensions | ExtensionType, tlv_data, extension lifecycle, anchor-spl token_2022_extensions | features-token-extensions |
| Example Programs | Curated program-examples repo—Basics, Tokens, Token 2022—when to use each | features-examples |
| Testing | Mollusk (Rust instruction harness), LiteSVM (Rust/TS/Python VM) | features-testing |
| Upgrade and Migrate | anchor upgrade, migrate script, upgrade authority | features-upgrade-migrate |
| 主题 | 描述 | 参考 |
|---|---|---|
| 事件 | emit!、emit_cpi!、addEventListener、解码 | features-events |
| 错误 | #[error_code]、err!、require!及其变体 | features-errors |
| 零拷贝 | AccountLoader、load_init/load_mut/load、init vs zero | features-zero-copy |
| declare_program! | 基于IDL的CPI和Rust客户端生成 | features-declare-program |
| 代币(SPL) | anchor-spl、铸币、代币账户、ATA、Token 2022、InterfaceAccount | features-tokens |
| Token 2022扩展 | ExtensionType、tlv_data、扩展生命周期、anchor-spl token_2022_extensions | features-token-extensions |
| 示例程序 | 精选program-examples仓库——基础示例、代币示例、Token 2022示例——及各场景适用说明 | features-examples |
| 测试 | Mollusk(Rust指令测试工具)、LiteSVM(Rust/TS/Python虚拟机) | features-testing |
| 升级与迁移 | anchor upgrade、迁移脚本、升级权限 | features-upgrade-migrate |
Clients
客户端
| Topic | Description | Reference |
|---|---|---|
| TypeScript | Program, methods, accounts, signers, rpc/transaction/instruction, fetch | clients-typescript |
| Rust | anchor-client, declare_program!, request/instructions/send, account fetch | clients-rust |
| 主题 | 描述 | 参考 |
|---|---|---|
| TypeScript | Program、方法、账户、签名者、rpc/交易/指令、获取数据 | clients-typescript |
| Rust | anchor-client、declare_program!、请求/指令/发送、账户数据获取 | clients-rust |
Best Practices
最佳实践
| Topic | Description | Reference |
|---|---|---|
| Security | Sealevel attacks, constraints, UncheckedAccount usage | best-practices-security |
| Constraints and Validation | When to use which constraints, avoid UncheckedAccount pitfalls | best-practices-constraints |
| 主题 | 描述 | 参考 |
|---|---|---|
| 安全 | Sealevel攻击、约束条件、UncheckedAccount使用 | best-practices-security |
| 约束与验证 | 各类约束的适用场景、规避UncheckedAccount陷阱 | best-practices-constraints |
Advanced
进阶内容
| Topic | Description | Reference |
|---|---|---|
| Verifiable Builds | anchor build --verifiable, verify, Docker | advanced-verifiable-builds |
| AVM | Anchor Version Manager, install, use, list | advanced-avm |
| 主题 | 描述 | 参考 |
|---|---|---|
| 可验证构建 | anchor build --verifiable、验证、Docker | advanced-verifiable-builds |
| AVM | Anchor版本管理器、安装、使用、列表查看 | advanced-avm |