I'm having trouble using confirmTransaction properly. I expect that the call won't return until the conditions are met (either it is confirmed or blockheight exceeded). However, I frequently get a response, but then an attempt to retrieve the transaction fails (returns null). Most of the time the transaction does go through, but it's already passed the point in my program where I am expecting to retrieve the transaction.

Other times, confirmTransaction returns a TransactionExpiredBlockheightExceededError error, but then an attempt to retrieve the transaction succeeds.

Ultimately, I need to understand how to properly use confirmTransaction to reliably determine when to retry a transaction.

Here's a snip

let latestBH = await solanaConnection.getLatestBlockhash('confirmed');
let confirmation = await solanaConnection.confirmTransaction({
    blockhash: latestBH.blockhash,
    lastValidBlockHeight: latestBH.lastValidBlockHeight,
    signature: txHash
}, 'confirmed');

// confirmation response
    "context": {
        "slot": 223810433
    "value": {
        "err": null

let txResult = await solanaConnection.getTransaction(txHash, {
    commitment: 'confirmed', 
    preflightCommitment: 'confirmed', 
    maxSupportedTransactionVersion: 1

2 Answers 2


It could be that you're sometimes hitting different backends that have forked.

For example, if the confirmation is expiring even though it's later confirmed, the node you're accessing could have forked off. On the other hand, if you're failing to retrieve the transaction later, it could be that the node you're accessing again forked off and never included that transaction.

As for retrying transactions, the idea is to gradually retry broadcasting until you're sure that it lands, and only re-sign if you know that it didn't go through. There's more information at https://solanacookbook.com/guides/retrying-transactions.html#retrying-transactions

  • I appreciate the response. So in the event that confirmTransaction returns and a subsequent getTransaction fails, does that mean the transaction did go through and I just need to wait to retrieve the transaction? At that point, is there still a chance that the transaction will fail?
    – Someone
    Commented Oct 17, 2023 at 13:18
  • if confirmTransaction works for the confirmed commitment, you can be practically sure that it went through. It's technically possible for the transaction to be reverted, but it has never happened in practice.
    – Jon C
    Commented Oct 17, 2023 at 16:01

what i usually fo is that i write a recursive function that calls itself every 5/10 secs to check if the transaction exists with the given signature, and then use the parsed transaction to check if there was an error. And you can stop this script after X attempts (but it doesn't really mean that the transaction didn't went thru, it could be that you haven't waited long enough).

  • Thank you for the insight. I was hoping to use confirmTransaction to perform this sort of logic more precisely. It could be that I need to use these concepts together – confirmTransaction followed by a polling of getTransaction.
    – Someone
    Commented Oct 17, 2023 at 13:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.