solana_kit_transaction_introspection

pub package CI coverage

Decode confirmed Solana transactions and walk their outer and inner instructions. walkInstructions returns every instruction in display order, with account indices resolved to AccountMetas ready for the @solana-program/* clients to identify and parse.

Key APIs

  • decodeTransactionFromRpcResponse(Map<String, Object?>?) decodes a getTransaction response ('base64', 'base58', or 'json') into a DecodedRpcTransaction (compiled message + loaded ALT addresses + wire-format transaction for binary encodings).
  • walkInstructions({compiledMessage, meta, loadedAddresses}) returns every instruction in display order as TracedInstructions (each outer instruction followed by its CPI inner instructions), with account indices resolved to AccountMetas.
  • getInstructionsFromCompiledTransactionMessage(compiledMessage, {loadedAddresses}) returns the outer instructions as resolved Instructions.
  • getInnerInstructionsFromMeta(meta, accountMetas) returns the inner instructions from a getTransaction meta as TracedInstructions.

Usage

void main() {
  // `rpcTx` is a Map<String, Object?> from a `getTransaction` RPC response.
  // final Map<String, Object?>? rpcTx = await rpc.getTransaction(...);
  // final decoded = decodeTransactionFromRpcResponse(rpcTx);
  // for (final ix in walkInstructions(
  //   compiledMessage: decoded.compiledMessage,
  //   loadedAddresses: decoded.loadedAddresses,
  // )) {
  //   print(ix.trace);
  //   print(ix.programAddress);
  // }
}

'jsonParsed' responses are not supported: their instructions arrive pre-parsed by the server and lack raw bytes, so they cannot be round-tripped through the auto-generated parseXInstruction clients. Prefer 'base64' when bandwidth allows. It is the most compact and the returned transaction is re-encodable.

RPC input is validated fail-closed. Mixed-type account/index arrays, unsupported transaction versions, incomplete compiled instructions, invalid header counts, malformed loaded addresses, duplicate inner-instruction groups, and inner-instruction groups that do not match an outer instruction throw a SolanaError instead of being silently dropped or misattributed.

Account resolution requires the writable and readonly loaded-address counts to match the v0 message's address table lookups exactly. Missing or extra addresses are rejected before instruction indices are resolved; legacy and v1 messages cannot accept loaded addresses. Decoding a response without loaded metadata remains possible, but lookup-dependent account resolution requires complete metadata. These structural checks do not authenticate an RPC provider's account addresses or execution metadata.

Libraries

solana_kit_transaction_introspection
Helpers for inspecting confirmed Solana transactions and walking their outer and inner instructions in a form that the auto-generated @solana-program/* clients can identify and parse directly.