Anchor
Anchor 是 Solana 的Sealevel运行时框架,为编写智能合约提供了几个方便的开发人员工具。
Solana 海平面框架
Anchor 是 Solana 的Sealevel运行时框架,为编写智能合约提供了几个方便的开发人员工具。
如果你熟悉以太坊的Solidity、Truffle、web3.js 开发,那么经验就会很熟悉。尽管 DSL 语法和语义针对的是 Solana,但编写 RPC 请求处理程序、发出 IDL 以及从 IDL 生成客户端的高级流程是相同的。
有关快速入门指南和深入教程,请参阅锚书和正在逐步淘汰的旧文档。要直接跳转到示例,请转到此处。有关最新的 Rust 和 TypeScript API 文档,请参阅docs.rs和typedoc。
这是一个计数器程序,只有指定的 authority
人才能增加计数。
use anchor_lang::prelude::*;
declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");
#[program]
mod counter {
use super::*;
pub fn initialize(ctx: Context<Initialize>, start: u64) -> Result<()> {
let counter = &mut ctx.accounts.counter;
counter.authority = *ctx.accounts.authority.key;
counter.count = start;
Ok(())
}
pub fn increment(ctx: Context<Increment>) -> 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,
}
Anchor 在Apache 2.0下获得许可。
除非您另有明确说明,否则您有意提交以包含在 Anchor 中的任何贡献(如 Apache-2.0 许可中所定义)均应按上述方式获得许可,而无需任何附加条款或条件。