2 releases
new 0.1.1 | Mar 13, 2025 |
---|---|
0.1.0 | Mar 6, 2025 |
#79 in #anchor
137 downloads per month
27KB
445 lines
anchor-decoder
A procedural macro to help with decoding Solana accounts and instructions for programs written with the Anchor framework.
Note: this tool relies on IDLs generated by Anchor 0.30.0. Fortunately, there's a CLI command to help convert legacy IDLs to the new format.
Usage
Add the crate to your Cargo.toml
, and point the macro at your IDL:
use anchor_decoder::anchor_idl;
#[anchor_idl("./idl.json")]
pub const ID: Pubkey = crate::ID;
You can create separate crates for each program. You can also call the macro multiple times in the same files by using separate modules.
pub mod production {
use anchor_decoder::anchor_idl;
#[anchor_idl("./production.json")]
pub const ID: Pubkey = crate::ID;
}
pub mod staging {
use anchor_decoder::anchor_idl;
#[anchor_idl("./staging.json")]
pub const ID: Pubkey = crate::ID;
}
For more examples, see the examples directory in the repository.
License
The project is licensed under Apache 2.0.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion by you, as defined in the Apache-2.0 license, shall be licensed as above, without any additional terms or conditions.
Contribution
Any contributions are welcome. If you notice there's an IDL that doesn't breaks the macro, please open an issue or submit a pull request.
Dependencies
~4.5MB
~85K SLoC