Skip to main content

declare_program

Macro declare_program 

Source
declare_program!() { /* proc-macro */ }
Expand description

Generates a module from an Anchor IDL JSON file.

Looks for idls/{name}.json by walking up from CARGO_MANIFEST_DIR.

§Generated items

  • ID — program Pubkey
  • accounts — account structs implementing AccountDeserialize
  • events — event structs with from_logs / from_cpi_logs
  • instructions — builder functions returning Instruction
  • types — shared structs, enums, and type aliases
  • constants — program constants
  • utilsEvent / Account wrapper enums

§Example

anchor_parser::declare_program!(my_program);

// Now use my_program::accounts, my_program::events, etc.

Generate a complete program module from an Anchor IDL JSON file.

Searches for idls/{name}.json by walking up from CARGO_MANIFEST_DIR.

§Generated items

  • ID — the program’s Pubkey
  • types — shared structs, enums, and type aliases
  • accounts — account structs with discriminator and deserialization
  • events — event structs with from_logs / from_cpi_logs parsers
  • instructions — builder functions → Result<Instruction, io::Error>
  • constants — program constants
  • utilsEvent / Account wrapper enums

§Example

anchor_parser::declare_program!(my_program);

// Use generated types:
use my_program::accounts::MyAccount;
use my_program::events::MyEvent;
use my_program::instructions;