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::*;.



  • Defines the program’s ID. This should be used at the root of all Anchor based programs.
  • Logs an event that can be subscribed to by clients. Uses the sol_log_data syscall which results in the following log:
  • 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.
  • 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





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 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.
  • 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.
  • 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)].

Derive Macros