Expand description
§anchor-parser
Generates Rust types and helpers from Anchor IDL JSON files using solana-sdk
types directly (no anchor-lang dependency).
§Generated modules
| Module | Contents |
|---|---|
accounts | Account structs with discriminators and deserialization |
events | Event structs with from_logs parsing |
instructions | Builder functions → solana_sdk::instruction::Instruction |
types | Shared structs, enums, and type aliases |
constants | Program constants |
utils | Event / Account wrapper enums for generic parsing |
§Usage
ⓘ
anchor_parser::declare_program!(my_program);
use my_program::accounts::MyAccount;
use my_program::events::MyEvent;
use my_program::instructions;
use my_program::constants;
use my_program::utils::Event;
// Build an instruction
let ix = instructions::update(
&my_program::ID,
&instructions::UpdateAccounts { authority, my_account },
42,
);
// Fetch an account (requires "client" feature)
use anchor_parser::client;
let account = client::fetch_account::<MyAccount>(&rpc_client, &address).await?;
let accounts = client::fetch_accounts::<MyAccount>(&rpc_client, &[addr1, addr2]).await?;
// Deserialize from raw account data
let account = MyAccount::from_account_data(&raw_bytes)?;
// Parse events from emit! logs
let events = MyEvent::from_logs(&log_messages);
let all_events = Event::from_logs(&log_messages);
// Parse events from emit_cpi! inner instruction data (bs58-encoded)
let events = MyEvent::from_cpi_logs(&inner_ix_data_strings);
let all_events = Event::from_cpi_logs(&inner_ix_data_strings);Macros§
- declare_
program - Declare a program module from an Anchor IDL JSON file.
Traits§
- Account
Deserialize - Trait implemented by generated account types.