Skip to main content
Anchor provides several powerful macros that reduce boilerplate and enforce security best practices.

Program macros

#[program]

Defines the module containing instruction handlers.

declare_id!

Declares the program’s on-chain address.
See Program Structure for more details.

Account macros

#[derive(Accounts)]

Validates and deserializes accounts for an instruction.

#[account]

Creates a custom account type with automatic serialization.

Event macros

#[event]

Defines an event that can be emitted.

emit!

Emits an event from your program.

Error macros

#[error_code]

Defines custom error codes.
See Errors for more details.

Constraint macros

require!

Assert a condition is true.

require_keys_eq!

Assert two public keys are equal.
See Account Constraints for all constraints.