solana_kit_transaction_introspection 0.9.3
solana_kit_transaction_introspection: ^0.9.3 copied to clipboard
Decode confirmed Solana transactions and walk their instructions for the auto-generated program clients.
solana_kit_transaction_introspection #
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 agetTransactionresponse ('base64','base58', or'json') into aDecodedRpcTransaction(compiled message + loaded ALT addresses + wire-format transaction for binary encodings).walkInstructions({compiledMessage, meta, loadedAddresses})returns every instruction in display order asTracedInstructions (each outer instruction followed by its CPI inner instructions), with account indices resolved toAccountMetas.getInstructionsFromCompiledTransactionMessage(compiledMessage, {loadedAddresses})returns the outer instructions as resolvedInstructions.getInnerInstructionsFromMeta(meta, accountMetas)returns the inner instructions from agetTransactionmetaasTracedInstructions.
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.