Module anchor_lang::prelude
source · 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::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::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::error;
pub use super::event;
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::Id;
pub use super::Key;
pub use super::Lamports;
pub use super::Owner;
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::*;
Macros§
- Defines the program’s ID. This should be used at the root of all Anchor based programs.
- Declare an external program based on its IDL.
- Logs an event that can be subscribed to by clients. Uses the
sol_log_data
syscall 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. - Returns with the given error. Use this with a custom error type.
- Generates an
Error::AnchorError
that includes file and line information. - Print a message to the log.
- Convenience macro to define a static public key.
- Ensures a condition is true, otherwise returns with the given error. Use this with or without a custom error type.
- Ensures two NON-PUBKEY values are equal.
- Ensures the first NON-PUBKEY value is greater than the second NON-PUBKEY value.
- Ensures the first NON-PUBKEY value is greater than or equal to the second NON-PUBKEY value.
- Ensures two pubkeys values are equal.
- Ensures two pubkeys are not equal.
- Ensures two NON-PUBKEY values are not equal.
- Creates a
Source
Structs§
- Account information
- Describes a single account read or written by a program during instruction execution.
- A representation of network time.
- Instructions sysvar, dummy type.
- The address of a Solana account.
- Configuration of network rent.
- A bitvector indicating which slots are present in the past epoch.
Enums§
- Reasons the program may fail
- Upgradeable loader account states
Traits§
- Borsh is the default serialization format for instructions and accounts. A data-structure that can be de-serialized from binary format by NBOR.
- 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. - A type that holds sysvar data.
Functions§
- Convenience function for accessing the next item in an
AccountInfo
iterator.
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.
- An attribute for a data structure representing a Solana account.
- A marker attribute used to mark const values that should be included in the generated IDL but functionally does nothing.
- Generates
Error
andtype Result<T> = Result<T, Error>
types to be used as return types from Anchor instruction handlers. Importantly, the attribute implementsFrom
on theErrorCode
to support converting from the user defined error enum into the generatedError
. - 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. - interface
interface-instructions
The#[interface]
attribute is used to mark an instruction as belonging to an interface implementation, thus transforming its discriminator to the proper bytes for that interface instruction. - The
#[program]
attribute defines the module containing all instruction handlers defining all entries into a Solana program. - 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)]
.