Summary
@solana/transaction-introspection turns a getTransaction RPC response into
a list of instructions with real addresses. It resolves account indices
(including lookup-table addresses), decodes inner CPI instructions, and walks
the full instruction tree in explorer order.Looking for how a program inspects sibling instructions onchain at runtime?
That is the Instructions sysvar - see Instruction
Introspection. This page
is about decoding a transaction offchain from an RPC response.
getTransaction response does not hand you a
ready-to-use list of instructions. Accounts are stored as numeric indices,
versioned transactions split
those accounts into static keys plus addresses loaded from
Address Lookup Tables, and
inner instructions from cross-program invocations (CPIs) arrive as encoded blobs
in the transaction metadata.
@solana/transaction-introspection does this resolution for you. It decodes the
wire transaction, maps every account index back to its Address, normalizes the
inner instructions, and returns instructions in the same outer-then-inner order
a block explorer shows. The returned instructions plug directly into the
codama-generated clients’ (e.g., @solana-program/* ) parseXInstruction
helpers.
Terminal
Decode the response
Fetch the transaction with a wire-format encoding and pass the response todecodeTransactionFromRpcResponse.
Decode a transaction
rpcTx, compiledMessage, and loadedAddresses
from this step.
Preparing for v1 transactionsThe v1 format is
active, so pass
maxSupportedTransactionVersion: 1 or the fetch fails on v1
transactions. decodeTransactionFromRpcResponse handles legacy, 0, and
1 alike (from @solana/kit 7.0). Note that a v1 message carries its
resource limits in a transactionConfig object rather than in ComputeBudget
instructions, so code that recovers compute limits or priority fees by
scanning the decoded instructions finds nothing for v1.Fetch with
base64, base58, or json encoding.
decodeTransactionFromRpcResponse rejects jsonParsed responses - that
encoding asks the RPC node to parse instructions server-side, so there is
nothing left to decode on the client.Walk the instructions
walkInstructions returns every instruction - outer and inner - as an array in
the order a block explorer shows: each outer instruction followed immediately by
the inner instructions its CPIs produced. Each instruction carries a trace
field describing where it sits in the call hierarchy.
Walk every instruction
trace is a discriminated union: { kind: "outer", index } for a top-level
instruction, or { kind: "inner", outerIndex, innerIndex, stackHeight? } for a
CPI instruction nested under an outer one.
meta is optional - pass rpcTx.meta directly even when it may be null. With
no meta, walkInstructions returns only the outer instructions.
Parse with a program client
Each instruction fromwalkInstructions is a ResolvedInstruction, so it works
directly with the predicates from @solana/instructions and the
identifyXInstruction / parseXInstruction helpers generated by the
@solana-program/* clients - no conversion step.
This example audits every Token Program SyncNative instruction in a
transaction, whether it ran at the top level or inside a CPI.
Find and parse SyncNative instructions
Lower-level helpers
walkInstructions covers most needs, but the package also exposes the pieces it
builds on:
getInstructionsFromCompiledTransactionMessage(compiledMessage, loadedAddresses?)returns only the outer instructions, with resolved accounts and decoded data.getInnerInstructionsFromMeta(meta, accountMetas)decodes the inner CPI instructions from the transaction metadata.getAccountMetasFromCompiledTransactionMessage(compiledMessage, loadedAddresses?)returns the full account list in transaction order - the input the previous helper needs to resolve inner-instruction account indices.
Resolve outer and inner instructions separately
Using Rust?There is no Rust equivalent of this package. To get parsed instructions from
Rust, request
UiTransactionEncoding::JsonParsed from
getTransaction and let the RPC node resolve
accounts and inner instructions for you.See also
- Transaction Structure - the anatomy of the response this package decodes
- Versioned Transactions - how Address Lookup Tables split accounts into static and loaded groups
getTransaction- the RPC method that returns the transaction