#solana #solana-anchor #generator #json-idl #anchor-gen #cpi #govern-cpi

macro anchor-generate-cpi-interface

Generates an Anchor CPI crate from a JSON IDL

3 unstable releases

0.4.0 May 9, 2025
0.3.1 Sep 27, 2022
0.3.0 Jul 26, 2022

#1 in #govern-cpi

Download history 2104/week @ 2025-03-26 1869/week @ 2025-04-02 3119/week @ 2025-04-09 2968/week @ 2025-04-16 3960/week @ 2025-04-23 2673/week @ 2025-04-30 1895/week @ 2025-05-07 4461/week @ 2025-05-14 3234/week @ 2025-05-21 3105/week @ 2025-05-28 6069/week @ 2025-06-04 4052/week @ 2025-06-11 3223/week @ 2025-06-18 1737/week @ 2025-06-25 1928/week @ 2025-07-02 2044/week @ 2025-07-09

9,199 downloads per month
Used in 37 crates (via anchor-gen)

Apache-2.0

44KB
793 lines

anchor-gen

Generates a crate for cross-program invocations to an Anchor program from a JSON IDL.

Usage

In a new crate, write:

anchor_gen::generate_cpi_crate!("../../examples/govern-cpi/idl.json");

declare_id!("GjphYQcbP1m3FuDyCTUJf2mUMxKPE3j6feWU1rxvC7Ps");

This will generate a fully functional Rust CPI client for your IDL.

More examples can be found in the examples/ directory.

Note: This does not work on legacy IDLs. To migrate a legacy IDL, use anchor idl convert idl.json.

License: Apache-2.0

Dependencies

~3MB
~67K SLoC