Crate anchor_lang
source · [−]Expand description
Anchor ⚓ is a framework for Solana’s Sealevel runtime providing several convenient developer tools.
- Rust eDSL for writing safe, secure, and high level Solana programs
- IDL specification
- TypeScript package for generating clients from IDL
- CLI and workspace management for developing complete applications
If you’re familiar with developing in Ethereum’s Solidity, Truffle, web3.js or Parity’s Ink!, then the experience will be familiar. Although the syntax and semantics are targeted at Solana, the high level workflow of writing RPC request handlers, emitting an IDL, and generating clients from IDL is the same.
For detailed tutorials and examples on how to use Anchor, see the guided tutorials or examples in the GitHub repository.
Presented here are the Rust primitives for building on Solana.
Re-exports
pub use solana_program;
Modules
idl.rs defines the instructions and account state used to store a program’s IDL.
The prelude contains all commonly used components of the crate.
All programs should include it via anchor_lang::prelude::*;
.
Structs
Provides non-argument inputs to the program.
Container for any account not owned by the current program.
Context speciying non-argument inputs for cross-program-invocations.
Boxed container for a deserialized account
. Use this to reference any
account owned by the currently executing program.
Boxed container for the program state singleton.
Container for sysvars.
Enums
Traits
A data structure that can be deserialized from an AccountInfo
data array.
A data structure that can be serialized and stored in an AccountInfo
data
array.
A data structure of accounts that can be deserialized from the input
of a Solana program. Due to the freewheeling nature of the accounts array,
implementations of this trait should perform any and all constraint checks
(in addition to any done within AccountDeserialize
) on accounts to ensure
the accounts maintain any invariants required for the program to run
securely.
The exit procedure for an accounts object.
A data structure of accounts providing a one time deserialization upon initialization, i.e., when the data array for a given account is zeroed. For all subsequent deserializations, it’s expected that Accounts is used.
Default serialization format for anchor instructions and accounts. A data-structure that can be de-serialized from binary format by NBOR.
Default serialization format for anchor instructions and accounts. A data-structure that can be serialized into binary format by NBOR.
Transformation to an AccountInfo
struct.
Transformation to AccountInfo
structs.
Transformation to AccountMeta
structs.
Attribute Macros
Executes the given access control method before running the decorated instruction handler. Any method in scope of the attribute can be invoked with any arguments from the associated instruction handler.
A data structure representing a Solana account.
Generates an error type from an error code enum.
The module containing all instruction handlers defining all entries to the Solana program.
Derive Macros
Implements an Accounts
deserializer on the given struct, applying any
constraints specified via #[account]
attributes.
Default serialization format for anchor instructions and accounts.
Default serialization format for anchor instructions and accounts.