Skip to content

goni098/shank-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

shank-parse

Crates.io Docs.rs License: MIT

A proc-macro crate that generates type-safe Rust client code at compile time from Shank / Anchor IDL JSON files for Solana programs.


Features

  • 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, and types submodules.

Installation

Add both crates to your Cargo.toml:

[dependencies]
shank-parse = "0.1"
solana-sdk = "3"

Usage

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).

Example — Counter program

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 },
    );
}

Generated submodules

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

IDL format

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>" }
}

Workspace layout

shank-parse/
├── lib/          # shank-parse — the public-facing crate
└── macro/        # shank-parse-macro — the proc-macro implementation

License

MIT — see LICENSE.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages