Search code examples
javascriptnode.jsblockchainsolanaanchor-solana

How to find out if a transaction is finalized on Solana


How do you get the current status of a transaction on Solana with the Solana Javascript API (@solana/web3.js)?

https://solscan.io/tx/4fwgX16WDwYj5hZ2t5xEHz6UUnuaTovJpMeoWWEBvuA7z1baf1qX1BW2EGZVR9ChSyJZ8akeLX6EDTadFcEcSTdy

This is what I've tried, but it only seems to work for recent transactions.

const { Connection, clusterApiUrl } = require("@solana/web3.js");

(async () => {
    const connection = new Connection(clusterApiUrl('mainnet-beta'));
    const status = await connection.getSignatureStatus("4fwgX16WDwYj5hZ2t5xEHz6UUnuaTovJpMeoWWEBvuA7z1baf1qX1BW2EGZVR9ChSyJZ8akeLX6EDTadFcEcSTdy");
    console.log(status);
})();

Solution

  • Try adding searchTransactionHistory: true to the SignatureStatusConfig

    const getConfirmation = async (connection: Connection, tx: string) => {
      const result = await connection.getSignatureStatus(tx, {
        searchTransactionHistory: true,
      });
      return result.value?.confirmationStatus;
    };
    

    https://docs.solana.com/developing/clients/jsonrpc-api#getsignaturestatuses