- IDL-based parsing — automatic deserialization using an Anchor IDL JSON. This is the preferred path when an IDL is available.
- Manual byte decoding — reading fields at known byte offsets. Use this for programs with custom binary serialization and no Anchor IDL.
IDL-based parsing
How it works
Thesolana-parser crate reads an Anchor IDL JSON, matches the 8-byte discriminator at the start of the instruction data, and deserializes the Borsh-encoded arguments into a JSON map. No manual byte offsets needed.
The result is a SolanaParsedInstructionData struct containing:
instruction_name— the matched instruction name from the IDLprogram_call_args— a map of argument names to deserialized values
Built-in IDLs
solana-parser ships with embedded program IDLs that are compiled into the binary and used automatically. See the ProgramType enum for the current list.
You only need to supply an IDL if your program isn’t already covered.
IDL structure
A minimal Anchor IDL JSON looks like this:discriminator— the first 8 bytes of the instruction data, used to identify which instruction is being calledaccounts— ordered list of accounts matching the transaction’s account indicesargs— Borsh-deserialized from the bytes after the discriminator
Loading a built-in IDL
ProgramType::from_program_id() returns Some if the program has a built-in IDL, then decode_idl_data() deserializes the JSON into an Idl struct.
Embedding your own IDL
Useinclude_str! to compile the IDL JSON into the binary:
CustomIdlConfig::from_json():
IdlRegistry in visualsign-solana manages both built-in and custom IDLs, checking custom configs first and falling back to built-in ProgramType lookups.
Parsing an instruction
parse_instruction_with_idl returns a SolanaParsedInstructionData with the instruction name and all arguments deserialized from the Borsh-encoded data.
Reference implementation: Jupiter swap preset
Manual byte decoding
When to use
Use manual byte decoding for programs that don’t have an Anchor IDL — programs with custom binary serialization where you need full control over how bytes are read.Pattern
Read a discriminator (the size varies per program — Anchor uses 8 bytes, but others may use 1, 2, or 4 bytes), match it to an instruction type, then parse fields at known byte offsets:- Always validate data length before reading at an offset
- Use little-endian byte order (
from_le_bytes) — this is standard for Solana - Define a structured error type with context about which field failed to parse
- Include an
Unknownvariant to handle unrecognized discriminators gracefully
Extending solana-parser
For a more generic, reusable solution, you can contribute a built-in IDL to thesolana-parser crate. This makes the IDL available to all consumers of the crate without any extra configuration. This is also the planned approach for supporting Codama-generated IDLs.