decodeTransactionFromRpcResponse

Call Signature

function decodeTransactionFromRpcResponse(rpcTx): Readonly<{
    compiledMessage: CompiledTransactionMessage &
        Readonly<{
            lifetimeToken: string;
        }>;
    loadedAddresses: LoadedAddresses;
    transaction?: Readonly<{
        messageBytes: TransactionMessageBytes;
        signatures: SignaturesMap;
    }>;
}> &
    object;

Decodes a confirmed-transaction RPC response (any of encoding: 'base64', 'base58', or 'json') into a CompiledTransactionMessage plus, for 'base64' and 'base58', a re-encodable Transaction. The JSON path does not produce a Transaction: the server has already decompiled the wire format, so there are no message bytes to carry.

Because it reads only the transaction / meta / version envelope — not a method-specific response shape — it accepts results from any method that returns confirmed transactions in these encodings: getTransaction, getTransactionsForAddress, and getBlock (the latter two with transactionDetails: 'full'). The array-returning methods just need a map:

const { data } = await rpc.getTransactionsForAddress(address, {
    encoding: 'base64',
    maxSupportedTransactionVersion: 0,
    transactionDetails: 'full',
}).send();
const decoded = data.map(tx => decodeTransactionFromRpcResponse(tx));
 
const block = await rpc.getBlock(slot, {
    encoding: 'base64',
    maxSupportedTransactionVersion: 0,
    transactionDetails: 'full',
}).send();
const decodedBlockTxs = block?.transactions.map(tx => decodeTransactionFromRpcResponse(tx)) ?? [];

'jsonParsed' is not supported — its instructions arrive pre-parsed by the server and lack raw bytes, so they cannot be round-tripped through the auto-generated parseXInstruction clients. Passing a 'jsonParsed' response throws SOLANA_ERROR__TRANSACTION_INTROSPECTION__CANNOT_DECODE_JSON_PARSED_TRANSACTION; any other unrecognized input throws SOLANA_ERROR__TRANSACTION_INTROSPECTION__UNRECOGNIZED_GET_TRANSACTION_RESPONSE.

A response carrying a transaction version this package cannot decode throws SOLANA_ERROR__TRANSACTION__VERSION_NUMBER_NOT_SUPPORTED — raised by the JSON path for an unrecognized version, and by the wire decoders for malformed binary input.

Use this together with getInstructionsFromCompiledTransactionMessage (or walkInstructions) to inspect a confirmed transaction's instructions in a form the auto-generated @solana-program/* clients can parse directly.

Prefer encoding: 'base64' when bandwidth allows — it is the most compact, the wire bytes round-trip cleanly through the kit codecs, and the return type statically guarantees a re-encodable transaction.

Parameters

ParameterType
rpcTxDecodableWireTransactionResponse

Returns

Readonly<{ compiledMessage: CompiledTransactionMessage & Readonly<{ lifetimeToken: string; }>; loadedAddresses: LoadedAddresses; transaction?: Readonly<{ messageBytes: TransactionMessageBytes; signatures: SignaturesMap; }>; }> & object

Example

const rpcResponse = await rpc.getTransaction(signature(txid), {
    commitment: 'confirmed',
    encoding: 'base64',
    maxSupportedTransactionVersion: 0,
}).send();
if (!rpcResponse) throw new Error('not found');
 
const { compiledMessage, loadedAddresses } = decodeTransactionFromRpcResponse(rpcResponse);
const instructions = getInstructionsFromCompiledTransactionMessage(compiledMessage, loadedAddresses);

Call Signature

function decodeTransactionFromRpcResponse(rpcTx): Readonly<{
    compiledMessage: CompiledTransactionMessage &
        Readonly<{
            lifetimeToken: string;
        }>;
    loadedAddresses: LoadedAddresses;
    transaction?: Readonly<{
        messageBytes: TransactionMessageBytes;
        signatures: SignaturesMap;
    }>;
}> &
    object;

Decodes a confirmed-transaction RPC response (any of encoding: 'base64', 'base58', or 'json') into a CompiledTransactionMessage plus, for 'base64' and 'base58', a re-encodable Transaction. The JSON path does not produce a Transaction: the server has already decompiled the wire format, so there are no message bytes to carry.

Because it reads only the transaction / meta / version envelope — not a method-specific response shape — it accepts results from any method that returns confirmed transactions in these encodings: getTransaction, getTransactionsForAddress, and getBlock (the latter two with transactionDetails: 'full'). The array-returning methods just need a map:

const { data } = await rpc.getTransactionsForAddress(address, {
    encoding: 'base64',
    maxSupportedTransactionVersion: 0,
    transactionDetails: 'full',
}).send();
const decoded = data.map(tx => decodeTransactionFromRpcResponse(tx));
 
const block = await rpc.getBlock(slot, {
    encoding: 'base64',
    maxSupportedTransactionVersion: 0,
    transactionDetails: 'full',
}).send();
const decodedBlockTxs = block?.transactions.map(tx => decodeTransactionFromRpcResponse(tx)) ?? [];

'jsonParsed' is not supported — its instructions arrive pre-parsed by the server and lack raw bytes, so they cannot be round-tripped through the auto-generated parseXInstruction clients. Passing a 'jsonParsed' response throws SOLANA_ERROR__TRANSACTION_INTROSPECTION__CANNOT_DECODE_JSON_PARSED_TRANSACTION; any other unrecognized input throws SOLANA_ERROR__TRANSACTION_INTROSPECTION__UNRECOGNIZED_GET_TRANSACTION_RESPONSE.

A response carrying a transaction version this package cannot decode throws SOLANA_ERROR__TRANSACTION__VERSION_NUMBER_NOT_SUPPORTED — raised by the JSON path for an unrecognized version, and by the wire decoders for malformed binary input.

Use this together with getInstructionsFromCompiledTransactionMessage (or walkInstructions) to inspect a confirmed transaction's instructions in a form the auto-generated @solana-program/* clients can parse directly.

Prefer encoding: 'base64' when bandwidth allows — it is the most compact, the wire bytes round-trip cleanly through the kit codecs, and the return type statically guarantees a re-encodable transaction.

Parameters

ParameterType
rpcTxDecodableJsonTransactionResponse

Returns

Readonly<{ compiledMessage: CompiledTransactionMessage & Readonly<{ lifetimeToken: string; }>; loadedAddresses: LoadedAddresses; transaction?: Readonly<{ messageBytes: TransactionMessageBytes; signatures: SignaturesMap; }>; }> & object

Example

const rpcResponse = await rpc.getTransaction(signature(txid), {
    commitment: 'confirmed',
    encoding: 'base64',
    maxSupportedTransactionVersion: 0,
}).send();
if (!rpcResponse) throw new Error('not found');
 
const { compiledMessage, loadedAddresses } = decodeTransactionFromRpcResponse(rpcResponse);
const instructions = getInstructionsFromCompiledTransactionMessage(compiledMessage, loadedAddresses);

On this page