Read transaction metadata with Solana getTransaction

Use Solana JSON-RPC getTransaction to inspect execution status, fees, balances, logs, and inner instructions for a transaction signature.

To inspect a Solana transaction, call the cluster’s getTransaction JSON-RPC method with its signature and a supported transaction version. The response’s meta field contains execution details such as err, fee, logMessages, and innerInstructions. This guide uses the public mainnet RPC URL; check the OnFinality Solana network page for network information and available access options.

Prepare a transaction signature

You need a transaction signature from the cluster you plan to query. The example below reads it from an environment variable so you can use a signature from your own application or explorer. Set SOLANA_SIGNATURE before running the request.

  • A transaction signature identifies one transaction; it is not a wallet address or block slot.
  • The example targets mainnet-beta. Use the corresponding cluster RPC URL if your signature is from another cluster.

Request the transaction and metadata

This Node.js 18+ script sends a JSON-RPC request to the public mainnet-beta URL. maxSupportedTransactionVersion: 0 lets the request handle legacy and version 0 transactions. The script checks HTTP status, JSON-RPC errors, missing transactions, and absent metadata so each failure has a useful explanation.

  • A successful response has a result containing the transaction and its meta object.
  • A null result means the RPC did not return that signature, which can happen when the signature is unavailable from that cluster or the transaction is not found. The script exits with an error in that case.
JavaScript · Node.js
const signature = process.env.SOLANA_SIGNATURE;
if (!signature) {
  console.error('Set SOLANA_SIGNATURE to a transaction signature first.');
  process.exit(1);
}

const response = await fetch('https://api.mainnet-beta.solana.com', {
  method: 'POST',
  headers: { 'content-type': 'application/json' },
  body: JSON.stringify({
    jsonrpc: '2.0',
    id: 1,
    method: 'getTransaction',
    params: [signature, {
      encoding: 'json',
      commitment: 'confirmed',
      maxSupportedTransactionVersion: 0
    }]
  })
});

if (!response.ok) {
  throw new Error(`RPC HTTP error: ${response.status} ${response.statusText}`);
}

const payload = await response.json();
if (payload.error) {
  throw new Error(`RPC error ${payload.error.code}: ${payload.error.message}`);
}
if (!payload.result) {
  throw new Error('Transaction not found in this RPC response; check the signature and cluster.');
}
if (!payload.result.meta) {
  throw new Error('Transaction response has no metadata to inspect.');
}

const { slot, blockTime, meta } = payload.result;
console.log(JSON.stringify({
  slot,
  blockTime,
  executionError: meta.err,
  feeLamports: meta.fee,
  preBalances: meta.preBalances,
  postBalances: meta.postBalances,
  logMessages: meta.logMessages,
  innerInstructions: meta.innerInstructions
}, null, 2));

Run it with SOLANA_SIGNATURE='your-signature' node get-transaction.mjs. The expected output is a JSON object with the transaction’s slot and block time, execution error (null when execution succeeded), fee in lamports, pre and post balances, program logs, and inner instructions. Values depend on the signature you provide; the example does not assume a particular transaction result.

When meta.err is non-null, the transaction failed during execution. Inspect logMessages for program output and innerInstructions for instructions invoked by programs. Either field can be null, so handle that possibility in downstream code.

Know what this request can answer

getTransaction is an RPC lookup for one known signature. It returns the transaction and its available execution metadata; it does not build an application-specific historical dataset or let you query a collection of transactions by arbitrary fields.

If your task is to find transactions across many accounts or apply repeatable filters, consider an indexing and querying workflow. Start with OnFinality Learn for developer guides, or use the RPC Assistant to help explore RPC methods.