walkInstructions

function walkInstructions(args): TracedInstruction[];

Returns every instruction in a confirmed transaction as TracedInstructions, in the order an explorer displays them: each outer instruction followed immediately by the inner instructions its CPIs produced.

Each returned instruction has its account indices resolved to AccountMetas and its data exposed as a ReadonlyUint8Array (omitted when empty), making it directly usable with the auto-generated @solana-program/* identifyXInstruction and parseXInstruction functions, and with isInstructionForProgram from @solana/instructions.

If meta is omitted, only outer instructions are returned. If loadedAddresses is omitted, only static accounts are used to resolve indices — pass meta?.loadedAddresses for v0 transactions that load accounts from address lookup tables.

Parameters

ParameterType
args{ compiledMessage: CompiledTransactionMessage; loadedAddresses?: | Readonly<{ readonly: readonly Address[]; writable: readonly Address[]; }> | null; meta?: | Readonly<{ innerInstructions?: | readonly Readonly<{ index: number; instructions: readonly TransactionInstruction[]; }>[] | null; }> | null; }
args.compiledMessageCompiledTransactionMessage
args.loadedAddresses?| Readonly<{ readonly: readonly Address[]; writable: readonly Address[]; }> | null
args.meta?| Readonly<{ innerInstructions?: | readonly Readonly<{ index: number; instructions: readonly TransactionInstruction[]; }>[] | null; }> | null

Returns

TracedInstruction[]

Example

import { isInstructionForProgram, isInstructionWithData } from '@solana/instructions';
import { TOKEN_PROGRAM_ADDRESS, identifyTokenInstruction, TokenInstruction } from '@solana-program/token';
 
const instructions = walkInstructions({ compiledMessage, meta, loadedAddresses });
for (const ix of instructions) {
    if (isInstructionForProgram(ix, TOKEN_PROGRAM_ADDRESS) &&
        isInstructionWithData(ix) &&
        identifyTokenInstruction(ix) === TokenInstruction.SyncNative) {
        console.log(ix.trace);
    }
}

On this page