Introducing a new way to review your PRs.

Read the announcement

solana-foundation / solana-go

Go SDK library and RPC client for the Solana Blockchain

View on GitHub

26 documents · Updated Nov 16, 2026

docs / local-transaction-inspection

Local transaction inspection

Local transaction inspection turns an available transaction message and its optional execution metadata into a safe, ordered view of the instructions that ran. It resolves each program and account reference, keeps top-level and cross-program instructions together, and leaves raw instruction data ready for program-specific decoding. See also Transaction introspection and RPC transaction introspection.

Inspection scope

The introspection package accepts legacy, version 0, and version 1 transaction messages. It can inspect a message by itself or combine it with transaction metadata that supplies loaded accounts and inner instructions. The result is useful for local tools that already have decoded transaction data and do not need the package to fetch anything.

The package supports these inspection inputs:

InputResult
Transaction messageTop-level instructions and their account context
Transaction message plus transaction metadataTop-level instructions interleaved with inner instructions
Resolved address lookups or supplied loaded addressesOne account list for all instruction indexes

References: introspection/doc.go• L15-59 introspection/introspection.go• L141-220

Account context

Account context maps the numeric indexes in a compiled instruction to account keys with signer and writable roles. The map starts with static message accounts and then adds writable and read-only accounts loaded through address lookups. This gives each returned instruction the same account view that its transaction uses.

For a message with address lookups, the inspector uses the first usable source below:

  • Loaded addresses from transaction metadata.
  • Accounts already resolved into the message.
  • Address tables attached to the message.

The input must provide enough information to resolve every lookup. The inspector does not change the message while it builds this context, and the returned account values are independent of the input data.

References: introspection/introspection.go• L141-172 introspection/introspection.go• L277-374

Instruction view

Each returned instruction exposes its program key, referenced account metadata, raw data, and a trace that identifies its place in the transaction. OuterInstructions returns only message instructions. InnerInstructions resolves execution instructions from metadata. Walk combines both views in explorer order.

The trace distinguishes a top-level instruction from an instruction emitted by a cross-program invocation (CPI). It records the parent top-level position, the position within the inner group, and the reported CPI depth when that value is available.

The following flow shows how local transaction data becomes a decoded instruction view.

flowchart LR
    M[Transaction message] --> A[Resolve account context]
    R[Optional transaction metadata] --> A
    A --> O[Resolve top-level instructions]
    A --> I[Resolve inner instructions]
    O --> W[Ordered instruction view]
    I --> W
    W --> D[Program-specific decoding]

References: introspection/introspection.go• L48-108 introspection/introspection.go• L174-246 introspection/example_test.go• L40-62

Program interpretation

The returned instruction implements the common Solana instruction interface, so callers can inspect its program key and raw data without knowing the target program in advance. A caller can then use a program package decoder or the registered decoder for that program to turn the raw instruction into a typed instruction.

Decoder use depends on the program package being imported so its decoder is registered. Decoding receives copies of the account and data values. A failed decode reports that the instruction format is not understood by the selected program decoder rather than changing the original inspection result.

References: introspection/introspection.go• L78-108 introspection/doc.go• L19-45 introspection/introspection_test.go• L555-598

Input and execution errors

The package reports unsupported transaction forms and malformed references as errors. It stops the affected inspection when an instruction points outside the resolved account list, and it identifies the instruction trace plus the bad program or account position.

Important error classes are:

ConditionReported meaning
Unsupported message or RPC versionThe transaction is newer than the supported legacy, 0, and 1 forms
Missing or mismatched loaded accountsAddress lookup data cannot produce the account list required by the message
Missing transaction messageThe input does not contain a transaction that can be inspected
jsonParsed inputRaw instruction data is unavailable for this inspection path
Out-of-range program or account indexA compiled instruction refers to an account that the transaction does not have
Unmatched inner-instruction groupThe group is preserved at the end of a walk so no reported instruction is lost

These errors separate an unsupported input from malformed transaction data. Callers can use the package sentinel errors and the detailed index error to decide whether to fetch the transaction again, supply address data, skip the item, or report corrupt input.

References: introspection/introspection.go• L26-45 introspection/introspection.go• L110-139 introspection/introspection.go• L205-218 introspection/rpc.go• L88-128

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the supported transaction version range aligned between message inspection and RPC-result inspection.
  • Keep address lookup ordering and writable/read-only roles aligned with the account indexes used by compiled instructions.
  • Preserve trace order when inner-instruction metadata contains groups that do not match a top-level instruction.
  • Keep raw instruction data available for program decoders; parsed-only transaction inputs cannot provide the same contract.
  • Keep detailed index errors tied to the trace so callers can locate malformed instructions.

Important failure modes

TriggerConsequenceGuard
A versioned message has lookups but no loaded addresses, resolved accounts, or address tablesAccount resolution fails before instructions are returnedSupply transaction metadata or resolve the lookups first
Loaded writable/read-only counts do not match the message lookupsThe account indexes can no longer be trustedTreat ErrLoadedAddressesMismatch as invalid input
An instruction uses a program or account index beyond the resolved listThe walk stops with an IndexErrorCheck the wrapped ErrIndexOutOfRange and its trace
A transaction is fetched with jsonParsed encodingRaw instruction data is absent, so typed decoding cannot runFetch with json, base58, base64, or base64+zstd encoding
Inner metadata names no existing top-level instructionThe group is appended after the normal walk orderTreat the trailing group as malformed input that was preserved for visibility

Key files

FileWhy to read it
introspection/introspection.goDefines the local inspection model, account context, instruction walk, traces, and index errors
introspection/doc.goStates the package boundary, supported transaction forms, and decoder relationship
introspection/rpc.goShows how RPC transaction values are converted into the local inspection inputs
introspection/example_test.goDemonstrates finding typed instructions across top-level and CPI execution