2021-09-22 05:05:56 +08:00
< div align = "center" >
2021-09-23 04:45:55 +08:00
< img height = "170x" src = "https://media.discordapp.net/attachments/813444514949103658/890278520553603092/export.png?width=746&height=746" / >
2021-01-01 07:48:06 +08:00
2021-09-22 05:05:56 +08:00
< h1 > Anchor< / h1 >
< p >
< strong > Solana Sealevel Framework< / strong >
< / p >
< p >
2021-11-29 13:15:34 +08:00
< a href = "https://github.com/project-serum/anchor/actions" > < img alt = "Build Status" src = "https://github.com/project-serum/anchor/actions/workflows/tests.yaml/badge.svg" / > < / a >
2021-09-22 05:05:56 +08:00
< a href = "https://project-serum.github.io/anchor/" > < img alt = "Tutorials" src = "https://img.shields.io/badge/docs-tutorials-blueviolet" / > < / a >
2022-02-17 23:40:09 +08:00
< a href = "https://discord.gg/PDeRXyVURd" > < img alt = "Discord Chat" src = "https://img.shields.io/discord/889577356681945098?color=blueviolet" / > < / a >
2021-09-22 05:05:56 +08:00
< a href = "https://opensource.org/licenses/Apache-2.0" > < img alt = "License" src = "https://img.shields.io/github/license/project-serum/anchor?color=blueviolet" / > < / a >
< / p >
< / div >
2021-01-03 10:14:38 +08:00
2021-09-08 13:57:02 +08:00
Anchor is a framework for Solana's [Sealevel ](https://medium.com/solana-labs/sealevel-parallel-processing-thousands-of-smart-contracts-d814b378192 ) runtime providing several convenient developer tools for writing smart contracts.
2021-01-01 08:14:35 +08:00
2021-01-23 16:18:50 +08:00
- Rust eDSL for writing Solana programs
2021-01-05 13:18:08 +08:00
- [IDL ](https://en.wikipedia.org/wiki/Interface_description_language ) specification
- TypeScript package for generating clients from IDL
- CLI and workspace management for developing complete applications
2021-01-01 08:14:35 +08:00
2021-09-08 13:57:02 +08:00
If you're familiar with developing in Ethereum's [Solidity ](https://docs.soliditylang.org/en/v0.7.4/ ), [Truffle ](https://www.trufflesuite.com/ ), [web3.js ](https://github.com/ethereum/web3.js ), then the experience will be familiar. Although the DSL syntax and semantics are targeted at Solana, the high level flow of writing RPC request handlers, emitting an IDL, and generating clients from IDL is the same.
2021-01-01 07:48:06 +08:00
2021-01-05 13:18:08 +08:00
## Getting Started
2021-01-01 07:48:06 +08:00
2022-02-23 09:33:46 +08:00
For a quickstart guide and in depth tutorials, see the [anchor book ](https://book.anchor-lang.com ) and the older [documentation ](https://project-serum.github.io/anchor/getting-started/introduction.html ) that is being phased out.
2021-05-11 04:12:20 +08:00
To jump straight to examples, go [here ](https://github.com/project-serum/anchor/tree/master/examples ). For the latest Rust and TypeScript API documentation, see [docs.rs ](https://docs.rs/anchor-lang ) and the [typedoc ](https://project-serum.github.io/anchor/ts/index.html ).
2021-01-24 09:38:23 +08:00
## Packages
2021-02-01 00:19:32 +08:00
| Package | Description | Version | Docs |
| :-- | :-- | :--| :-- |
| `anchor-lang` | Rust primitives for writing programs on Solana | [![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` | CPI clients for SPL programs on Solana | ![crates ](https://img.shields.io/crates/v/anchor-spl?color=blue ) | [![Docs.rs ](https://docs.rs/anchor-spl/badge.svg )](https://docs.rs/anchor-spl) |
| `anchor-client` | Rust client for Anchor programs | ![crates ](https://img.shields.io/crates/v/anchor-client?color=blue ) | [![Docs.rs ](https://docs.rs/anchor-client/badge.svg )](https://docs.rs/anchor-client) |
2021-05-11 04:12:20 +08:00
| `@project-serum/anchor` | TypeScript client for Anchor programs | [![npm ](https://img.shields.io/npm/v/@project-serum/anchor.svg?color=blue )](https://www.npmjs.com/package/@project-serum/anchor) | [![Docs ](https://img.shields.io/badge/docs-typedoc-blue )](https://project-serum.github.io/anchor/ts/index.html) |
2021-11-05 00:37:19 +08:00
| `@project-serum/anchor-cli` | CLI to support building and managing an Anchor workspace | [![npm ](https://img.shields.io/npm/v/@project-serum/anchor-cli.svg?color=blue )](https://www.npmjs.com/package/@project-serum/anchor-cli) | [![Docs ](https://img.shields.io/badge/docs-typedoc-blue )](https://project-serum.github.io/anchor/cli/commands.html) |
2021-05-11 04:12:20 +08:00
2021-01-05 13:18:08 +08:00
## Note
2021-01-01 07:48:06 +08:00
2021-01-05 13:18:08 +08:00
* **Anchor is in active development, so all APIs are subject to change.**
* **This code is unaudited. Use at your own risk.**
2021-01-01 07:48:06 +08:00
2021-01-23 16:18:50 +08:00
## Examples
2021-07-12 05:07:19 +08:00
Here's a counter program, where only the designated `authority`
2021-01-23 16:18:50 +08:00
can increment the count.
2021-01-15 17:35:35 +08:00
```rust
2021-08-11 02:43:06 +08:00
use anchor_lang::prelude::*;
2021-01-01 07:48:06 +08:00
2021-09-08 13:57:02 +08:00
declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");
2021-01-01 07:48:06 +08:00
#[program]
2021-01-23 16:18:50 +08:00
mod counter {
2021-01-05 13:18:08 +08:00
use super::*;
2022-02-23 09:33:46 +08:00
pub fn initialize(ctx: Context< Initialize > , start: u64) -> Result< ()> {
2021-01-23 16:18:50 +08:00
let counter = & mut ctx.accounts.counter;
2021-09-04 21:13:41 +08:00
counter.authority = *ctx.accounts.authority.key;
counter.count = start;
2021-01-05 13:18:08 +08:00
Ok(())
}
2022-02-23 09:33:46 +08:00
pub fn increment(ctx: Context< Increment > ) -> Result< ()> {
2021-01-23 16:18:50 +08:00
let counter = & mut ctx.accounts.counter;
2021-07-17 01:35:01 +08:00
counter.count += 1;
2021-01-10 14:31:40 +08:00
Ok(())
2021-01-01 07:48:06 +08:00
}
}
2021-01-01 08:14:35 +08:00
#[derive(Accounts)]
2021-01-01 07:48:06 +08:00
pub struct Initialize< 'info> {
2021-09-04 21:13:41 +08:00
#[account(init, payer = authority, space = 48)]
2021-09-08 13:57:02 +08:00
pub counter: Account< 'info, Counter>,
2021-09-17 06:49:24 +08:00
pub authority: Signer< 'info>,
pub system_program: Program< 'info, System>,
2021-01-05 13:18:08 +08:00
}
#[derive(Accounts)]
2021-01-23 16:18:50 +08:00
pub struct Increment< 'info> {
2021-01-21 09:38:23 +08:00
#[account(mut, has_one = authority)]
2021-09-08 13:57:02 +08:00
pub counter: Account< 'info, Counter>,
2021-09-17 06:49:24 +08:00
pub authority: Signer< 'info>,
2021-01-01 07:48:06 +08:00
}
2021-01-10 14:31:40 +08:00
#[account]
2021-01-23 16:18:50 +08:00
pub struct Counter {
2021-01-10 14:31:40 +08:00
pub authority: Pubkey,
2021-01-23 16:18:50 +08:00
pub count: u64,
2021-01-01 07:48:06 +08:00
}
```
2021-01-24 09:38:23 +08:00
For more, see the [examples ](https://github.com/project-serum/anchor/tree/master/examples )
2021-09-08 14:00:22 +08:00
and [tests ](https://github.com/project-serum/anchor/tree/master/tests ) directories.
2021-01-24 09:38:23 +08:00
2022-02-18 09:07:32 +08:00
## License
Anchor is licensed under [Apache 2.0 ](./LICENSE ).
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in Anchor by you, as defined in the Apache-2.0 license, shall be
licensed as above, without any additional terms or conditions.
2021-04-08 01:11:26 +08:00
## Contribution
2022-02-23 09:33:46 +08:00
Thank you for your interest in contributing to Anchor!
Please see the [CONTRIBUTING.md ](./CONTRIBUTING.md ) to learn how.
2021-04-08 01:11:26 +08:00
2022-02-18 09:07:32 +08:00
### Thanks ❤️
2021-02-23 00:21:21 +08:00
2022-02-18 09:07:32 +08:00
< div align = "center" >
< a href = "https://github.com/project-serum/anchor/graphs/contributors" >
< img src = "https://contrib.rocks/image?repo=project-serum/anchor" width = "100%" / >
< / a >
< / div >