Skip to main content

Module prelude

Module 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::lazy_account::LazyAccount;lazy-account
pub 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_data syscall which results in the following log:
emit_cpievent-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::AnchorError that 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§

AccountInfo
Account information
AccountMeta
Describes a single account read or written by a program during instruction execution.
AnchorError
Clock
A representation of network time.
EpochSchedule
Instructions
Instructions sysvar, dummy type.
ProgramErrorWithOrigin
Pubkey
The address of a Solana account.
Rent
Configuration of network rent.
Rewards
SlotHashes
SlotHistory
A bitvector indicating which slots are present in the past epoch.
Source
StakeHistory

Enums§

ComparedValues
Error
ErrorCode
Error codes that can be returned by internal framework code.
ErrorOrigin
ProgramError
Reasons the program may fail
UpgradeableLoaderState
Upgradeable loader account states

Constants§

ERROR_CODE_OFFSET
The starting point for user defined error codes.

Traits§

AnchorDeserialize
Borsh is the default serialization format for instructions and accounts. A data-structure that can be de-serialized from binary format by NBOR.
AnchorSerialize
A data-structure that can be serialized into binary format by NBOR.
IdlBuildidl-build
A trait that types must implement in order to include the type in the IDL definition.
SolanaSysvar
Interface for loading a sysvar.

Functions§

next_account_info
Convenience function for accessing the next item in an AccountInfo iterator.

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 Error and type Result<T> = Result<T, Error> types to be used as return types from Anchor instruction handlers. Importantly, the attribute implements From on the ErrorCode to support converting from the user defined error enum into the generated Error.
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_cpievent-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 Accounts deserializer on the given struct. Can provide further functionality through the use of attributes.
AnchorDeserialize
Implements borsh deserialization for this structure, as well as implementing lazy deserialization if the lazy-account feature is enabled. #[borsh(use_discriminant = false)] is supported with lazy-account; use_discriminant = true and other #[borsh] attributes (e.g. skip) are not yet supported in conjunction with lazy-account.
AnchorSerialize
InitSpace
Implements a Space trait on the given struct or enum.