Macro switchboard_solana::prelude::declare_program
declare_program!() { /* proc-macro */ }
Expand description
Declare an external program based on its IDL.
The IDL of the program must exist in a directory named idls
. This directory can be at any
depth, e.g. both inside the program’s directory (<PROGRAM_DIR>/idls
) and inside Anchor
workspace root directory (<PROGRAM_DIR>/../../idls
) are valid.
§Usage
declare_program!(program_name);
This generates a module named program_name
that can be used to interact with the program
without having to add the program’s crate as a dependency.
Both on-chain and off-chain usage is supported.
Use cargo doc --open
to see the generated modules and their documentation.
§Note
Re-defining the same program to use the same definitions should be avoided since this results in a larger binary size.
A program should only be defined once. If you have multiple programs that depend on the same definition, you should consider creating a separate crate for the external program definition and reusing it in your programs.
§Example
A full on-chain CPI usage example can be found here.