Understanding Anchor Macros

Chapter 4: Understanding Anchor Macros

Anchor uses macros to streamline Solana program development.

Macros

  • declare_id!(): Sets the program’s on-chain address.

  • #[program]: Defines instruction handlers.

  • #[derive(Accounts)]: Specifies accounts for instructions.

  • #[error_code]: Defines custom error types.


Page Layout:

  • Header: Fixed top bar with "Solana Learn" logo, navigation, and profile icon.

  • Main Content:

    • Left Panel (60%): This text content.

    • Right Panel (40%): Code snippets for each macro.

  • Footer: Link to Anchor Macro Docs.

Visuals:

  • Code Snippets: Highlighted examples (e.g., declare_id!("...")).

  • Icons: Key (declare_id!), Gear (#[program]).

Interactivity:

  • Hover over snippets to highlight macro usage.

Last updated