solana-foundation/anchor

GitHub: solana-foundation/anchor

Anchor 是目前最流行的 Solana 程序开发框架,通过 Rust eDSL 和 TypeScript 工具链极大简化了智能合约的编写、测试与部署流程。

Stars: 5020 | Forks: 1903

Anchor

Solana 程序框架

Build Status Tutorials Discord Chat License

[Anchor](https://www.anchor-lang.com/) 是一个框架,提供了多种便捷的开发者工具,用于编写 Solana 程序(有时称为“智能合约”)。 - 用于编写 Solana 程序的 Rust eDSL - [IDL](https://en.wikipedia.org/wiki/Interface_description_language) 规范 - 用于从 IDL 生成客户端的 TypeScript 包 - 用于开发完整应用程序的 CLI 和工作区管理 Anchor 是最流行的 Solana 程序框架。 ## 快速入门 有关快速入门指南和深入教程,请参阅 [Anchor book](https://book.anchor-lang.com) 和 [Anchor 文档](https://anchor-lang.com)。 若要直接查看示例,请前往[此处](https://github.com/solana-foundation/anchor/tree/master/examples)。有关最新的 Rust 和 TypeScript API 文档,请参阅 [docs.rs](https://docs.rs/anchor-lang) 和 [typedoc](https://www.anchor-lang.com/docs/clients/typescript)。 ## 软件包 | 软件包 | 描述 | 版本 | 文档 | | :---------------------- | :------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------------------------------- | | `anchor-lang` | 用于在 Solana 上编写程序的 Rust 原语 | [![Crates.io](https://img.shields.io/crates/v/anchor-lang?color=blue)](https://crates.io/crates/anchor-lang) | [![Docs.rs](https://docs.rs/anchor-lang/badge.svg)](https://docs.rs/anchor-lang) | | `anchor-spl` | Solana 上 SPL 程序的 CPI 客户端 | [![crates](https://img.shields.io/crates/v/anchor-spl?color=blue)](https://crates.io/crates/anchor-spl) | [![Docs.rs](https://docs.rs/anchor-spl/badge.svg)](https://docs.rs/anchor-spl) | | `anchor-client` | Anchor 程序的 Rust 客户端 | [![crates](https://img.shields.io/crates/v/anchor-client?color=blue)](https://crates.io/crates/anchor-client) | [![Docs.rs](https://docs.rs/anchor-client/badge.svg)](https://docs.rs/anchor-client) | | `@anchor-lang/core` | Anchor 程序的 TypeScript 客户端 | [![npm](https://img.shields.io/npm/v/@anchor-lang/core.svg?color=blue)](https://www.npmjs.com/package/@anchor-lang/core) | [![Docs](https://img.shields.io/badge/docs-typedoc-blue)](https://solana-foundation.github.io/anchor/ts/index.html) | | `@anchor-lang/cli` | 用于支持构建和管理 Anchor 工作区的 CLI | [![npm](https://img.shields.io/npm/v/@anchor-lang/cli.svg?color=blue)](https://www.npmjs.com/package/@anchor-lang/core-cli) | [![Docs](https://img.shields.io/badge/docs-typedoc-blue)](https://www.anchor-lang.com/docs/references/cli) | ## 注意 - **Anchor 正在积极开发中,因此所有 API 都可能发生变化。** - **此代码未经审计。使用风险自负。** ## 示例 这是一个计数器程序,只有指定的 `authority`(授权方) 才能增加计数。 ``` use anchor_lang::prelude::*; declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS"); #[program] mod counter { use super::*; pub fn initialize(ctx: Context, start: u64) -> Result<()> { let counter = &mut ctx.accounts.counter; counter.authority = *ctx.accounts.authority.key; counter.count = start; Ok(()) } pub fn increment(ctx: Context) -> Result<()> { let counter = &mut ctx.accounts.counter; counter.count += 1; Ok(()) } } #[derive(Accounts)] pub struct Initialize<'info> { #[account(init, payer = authority, space = 48)] pub counter: Account<'info, Counter>, pub authority: Signer<'info>, pub system_program: Program<'info, System>, } #[derive(Accounts)] pub struct Increment<'info> { #[account(mut, has_one = authority)] pub counter: Account<'info, Counter>, pub authority: Signer<'info>, } #[account] pub struct Counter { pub authority: Pubkey, pub count: u64, } ``` 欲了解更多信息,请参阅 [examples](https://github.com/solana-foundation/anchor/tree/master/examples) 和 [tests](https://github.com/solana-foundation/anchor/tree/master/tests) 目录。 ## 许可证 Anchor 在 [Apache 2.0](./LICENSE) 许可证下授权。 除非您明确说明,否则您有意提交 以纳入 Anchor 的任何贡献,如 Apache-2.0 许可证中所定义,均应 按上述方式授权,没有任何附加条款或条件。 ## 贡献 感谢您有兴趣为 Anchor 做出贡献! 请参阅 [CONTRIBUTING.md](./CONTRIBUTING.md) 以了解如何操作。 ### 致谢 ❤️
标签:Anchor, Apache-2.0, CLI, DApp, DNS解析, eDSL, IDL, Rust, Rust开发, Solana, Solana程序, TypeScript, Web3, WiFi技术, XML注入, 加密货币, 区块链, 区块链开发工具, 去中心化应用, 可视化界面, 安全插件, 客户端生成, 工作空间管理, 开发框架, 开源项目, 智能合约, 网络流量审计, 通知系统