A proc-macro crate that generates type-safe Rust client code at compile time from Shank / Anchor IDL JSON files for Solana programs.
- Zero boilerplate — point the macro at an IDL file and get fully-typed instruction builders, account deserializers, event decoders, and a program-ID constant.
- Compile-time code generation — the IDL is read and transformed during
cargo build; no runtime overhead. - Supports Shank & Anchor IDL format — works with any IDL that follows the common Shank/Anchor JSON schema.
- Submodule layout — generated code is organized into
instructions,accounts,events, andtypessubmodules.
Add both crates to your Cargo.toml:
[dependencies]
shank-parse = "0.1"
solana-sdk = "3"Place your IDL JSON file anywhere inside your crate (e.g. idl/my_program.json) and invoke the macro once:
shank_parse::shank_parse!("idl/my_program.json");The path is resolved relative to your crate's root (CARGO_MANIFEST_DIR).
Given idl/counter.json (a Shank IDL with an InitCounter and IncreaseCounter instruction):
shank_parse::shank_parse!("idl/counter.json");
use counter::accounts::Counter;
use counter::instructions::init_counter;
use counter::ID;
fn main() {
// Program-ID constant derived from metadata.address in the IDL
println!("Program ID: {}", ID);
// Build an InitCounter instruction
let ix = init_counter(
payer,
counter_key,
system_program::ID,
InitCounterArgs { initial_value: 0 },
);
}| Submodule | Contents |
|---|---|
<program>::instructions |
Instruction builder functions and argument structs |
<program>::accounts |
Account structs with from_account_data deserializers |
<program>::events |
Event structs with discriminant-based decoding |
<program>::types |
Shared domain enums used across instructions |
<program>::ID |
Pubkey constant from metadata.address in the IDL |
The macro expects a JSON file following the Shank/Anchor IDL schema:
{
"version": "0.1.0",
"name": "counter",
"instructions": [...],
"accounts": [...],
"types": [...],
"errors": [...],
"metadata": { "address": "<base58 program id>" }
}shank-parse/
├── lib/ # shank-parse — the public-facing crate
└── macro/ # shank-parse-macro — the proc-macro implementation
MIT — see LICENSE.