Skip to Content
DocumentationRpcGet Transaction

Get Transaction

The getTransaction function retrieves detailed information about a transaction by its signature.

Usage

const transaction = await connection.getTransaction(signature);

Parameters

  • signature: string - The transaction signature to look up
  • commitment: Commitment (optional) - Confirmation level to use (default: “finalized”)
    • "processed" - Processed by current node
    • "confirmed" - Confirmed by supermajority of the cluster
    • "finalized" - Confirmed by supermajority and unlikely to revert
  • maxSupportedTransactionVersion: number (optional) - Maximum transaction version to return (default: 0)

Returns

Returns a Promise<Object | null>:

  • Object containing transaction details if found
  • null if the transaction doesn’t exist

The transaction object includes:

  • slot: The slot in which the transaction was processed
  • transaction: The transaction data including signatures and message
  • meta: Transaction metadata including fee, logs, and account changes
  • blockTime: Estimated production time as Unix timestamp

Example

// Get transaction details const signature = "5j7s6NiJS3JAkvgkoc18WVAsiSaci2pxB2A6ueCJP4tprA2TFg9wSyTLeYouxPBJEMzJinENTkpA52YStRW5Dia7"; const transaction = await connection.getTransaction(signature); if (transaction) { console.log(`Transaction found in slot: ${transaction.slot}`); console.log(`Block time: ${new Date(transaction.blockTime! * 1000).toISOString()}`); console.log(`Fee: ${transaction.meta?.fee} lamports`); // Access transaction logs if (transaction.meta?.logMessages) { console.log("Transaction logs:"); transaction.meta.logMessages.forEach(log => console.log(log)); } // Check if transaction succeeded if (transaction.meta?.err) { console.log("Transaction failed with error:", transaction.meta.err); } else { console.log("Transaction succeeded"); } } else { console.log("Transaction not found"); } // Get with specific commitment const recentTx = await connection.getTransaction(signature, "confirmed"); // Support versioned transactions const versionedTx = await connection.getTransaction( signature, "finalized", 1 // Support version 0 and version 1 transactions );

Use Cases

  • Debugging failed transactions
  • Analyzing transaction logs and account changes
  • Building transaction explorers
  • Auditing transaction history
  • Verifying transaction execution details

Notes

  • Returns null if the transaction is not found
  • Transactions may not be available if they are too old (RPC nodes typically keep ~2-3 days)
  • Use “finalized” commitment for confirmed transactions that won’t be rolled back
  • The maxSupportedTransactionVersion parameter allows fetching versioned transactions
  • Transaction logs are available in meta.logMessages
  • Account balance changes are in meta.preBalances and meta.postBalances
Last updated on