solana_kit_transaction_introspection

pub package CI coverage

Decode confirmed Solana transactions and walk their outer and inner instructions in a form that the auto-generated @solana-program/* clients can identify and parse directly.

This is the Dart port of @solana/transaction-introspection from the Solana TypeScript SDK.

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

import 'package:solana_kit_transaction_introspection/solana_kit_transaction_introspection.dart';

void main() {
  // `rpcTx` is a `getTransaction` response map.
  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, and inner-instruction groups that do not match an outer instruction throw a SolanaError instead of being silently dropped or misattributed.

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.