Expand description
The prelude contains all commonly used components of the crate.
All programs should include it via anchor_lang::prelude::*;.
Re-exports§
pub use super::accounts::lazy_account::LazyAccount;lazy-accountpub use crate as anchor_lang;pub use super::accounts::account::Account;pub use super::accounts::account_loader::AccountLoader;pub use super::accounts::interface::Interface;pub use super::accounts::interface_account::InterfaceAccount;pub use super::accounts::migration::Migration;pub use super::accounts::program::Program;pub use super::accounts::signer::Signer;pub use super::accounts::system_account::SystemAccount;pub use super::accounts::sysvar::Sysvar;pub use super::accounts::unchecked_account::UncheckedAccount;pub use super::context::Context;pub use super::context::CpiContext;pub use super::err;pub use super::error;pub use super::require;pub use super::require_eq;pub use super::require_gt;pub use super::require_gte;pub use super::require_keys_eq;pub use super::require_keys_neq;pub use super::require_neq;pub use super::source;pub use super::system_program::System;pub use super::AccountDeserialize;pub use super::AccountSerialize;pub use super::Accounts;pub use super::AccountsClose;pub use super::AccountsExit;pub use super::Discriminator;pub use super::DuplicateMutableAccountKeys;pub use super::Id;pub use super::Key;pub use super::Lamports;pub use super::Owner;pub use super::Owners;pub use super::ProgramData;pub use super::Result;pub use super::Space;pub use super::ToAccountInfo;pub use super::ToAccountInfos;pub use super::ToAccountMetas;pub use borsh;pub use thiserror;pub use error;pub use borsh;pub use thiserror;pub use crate::solana_program::*;
Macros§
- declare_
id - Defines the program’s ID. This should be used at the root of all Anchor based programs.
- declare_
program - Declare an external program based on its IDL.
- emit
- Logs an event that can be subscribed to by clients.
Uses the
sol_log_datasyscall which results in the following log: - emit_
cpi event-cpi - Log an event by making a self-CPI that can be subscribed to by clients.
- err
- Returns with the given error. Use this with a custom error type.
- error
- Generates an
Error::AnchorErrorthat includes file and line information. - pubkey
- Convenience macro to define a static public key.
- require
- Ensures a condition is true, otherwise returns with the given error. Use this with or without a custom error type.
- require_
eq - Ensures two NON-PUBKEY values are equal.
- require_
gt - Ensures the first NON-PUBKEY value is greater than the second NON-PUBKEY value.
- require_
gte - Ensures the first NON-PUBKEY value is greater than or equal to the second NON-PUBKEY value.
- require_
keys_ eq - Ensures two pubkeys values are equal.
- require_
keys_ neq - Ensures two pubkeys are not equal.
- require_
neq - Ensures two NON-PUBKEY values are not equal.
- source
- Creates a
Source
Structs§
- Account
Info - Account information
- Account
Meta - Describes a single account read or written by a program during instruction execution.
- Anchor
Error - Clock
- A representation of network time.
- Epoch
Schedule - Instructions
- Instructions sysvar, dummy type.
- Program
Error With Origin - Pubkey
- The address of a Solana account.
- Rent
- Configuration of network rent.
- Rewards
- Slot
Hashes - Slot
History - A bitvector indicating which slots are present in the past epoch.
- Source
- Stake
History
Enums§
- Compared
Values - Error
- Error
Code - Error codes that can be returned by internal framework code.
- Error
Origin - Program
Error - Reasons the program may fail
- Upgradeable
Loader State - Upgradeable loader account states
Constants§
- ERROR_
CODE_ OFFSET - The starting point for user defined error codes.
Traits§
- Anchor
Deserialize - Borsh is the default serialization format for instructions and accounts. A data-structure that can be de-serialized from binary format by NBOR.
- Anchor
Serialize - A data-structure that can be serialized into binary format by NBOR.
- IdlBuild
idl-build - A trait that types must implement in order to include the type in the IDL definition.
- Solana
Sysvar - Interface for loading a sysvar.
Functions§
- next_
account_ info - Convenience function for accessing the next item in an
AccountInfoiterator.
Attribute Macros§
- access_
control - Executes the given access control methods before running the decorated
instruction handler. Any method in scope of the attribute can be invoked
with any arguments from the associated instruction handler. Each method
must return
Result<()>. - account
- An attribute for a data structure representing a Solana account.
- constant
- A marker attribute used to mark const values that should be included in the generated IDL but functionally does nothing.
- error_
code - Generates
Errorandtype Result<T> = Result<T, Error>types to be used as return types from Anchor instruction handlers. Importantly, the attribute implementsFromon theErrorCodeto support converting from the user defined error enum into the generatedError. - event
- The event attribute allows a struct to be used with emit! so that programs can log significant events in their programs that clients can subscribe to. Currently, this macro is for structs only.
- event_
cpi event-cpi - An attribute macro to add necessary event CPI accounts to the given accounts struct.
- instruction
- This attribute is used to override the Anchor defaults of program instructions.
- program
- The
#[program]attribute defines the module containing all instruction handlers defining all entries into a Solana program. - zero_
copy - A data structure that can be used as an internal field for a zero copy
deserialized account, i.e., a struct marked with
#[account(zero_copy)].
Derive Macros§
- Accounts
- Implements an
Accountsdeserializer on the given struct. Can provide further functionality through the use of attributes. - Anchor
Deserialize - Implements
borshdeserialization for this structure, as well as implementing lazy deserialization if thelazy-accountfeature is enabled.#[borsh(use_discriminant = false)]is supported withlazy-account;use_discriminant = trueand other#[borsh]attributes (e.g.skip) are not yet supported in conjunction withlazy-account. - Anchor
Serialize - Init
Space - Implements a
Spacetrait on the given struct or enum.