1

I am getting an error message when creating a signature

Error: 

TransactionExpiredBlockheightExceededError: Signature 2XqzFuyv5YWpDPTT87CVu48QJPemGSu5rbCazrNBgY6D3mS8rugKugtzXDGpN6XZF8FPyWwXQvzfm4ZyMx6gTf6j has expired: block height exceeded.

Signature created like this:

const transaction = program.methods(...)

  transaction.feePayer = publicKey;
          transaction.recentBlockhash = (await connection.getLatestBlockhash()).blockhash;
          const latestBlockHash = await connection.getLatestBlockhash()

// ----> Phantom recommended way of signing tx
          const { signature }  = await provider.signAndSendTransaction(transaction);

 const confirmation = await connection.confirmTransaction(
            {
              blockhash: latestBlockHash.blockhash,
              lastValidBlockHeight: latestBlockHash.lastValidBlockHeight,
              signature,
            }
          );

After few seconds/minute or 2 I get the above error message although the TX is confirmed and finalized.

How to handle this? Why is the error popping up if the tx gets added to the block?

Digital Dom
  • 412
  • 5
  • 12

1 Answers1

2

Transaction failure is a tricky situation, and web3.js currently doesn't do a great job at making it clear what's going on.

This error specifically means that the transaction was signed using a blockhash that (normally) won't be included in any new block. If you ever get to the point that the blockhash is too old, you'll need to fetch a new one, re-sign the transaction, and send it again.

Before doing that, however, you can try to resend your previous transaction. It could be that it was sent to a leader that didn't include it, and then wasn't forwarded to another leader for some reason.

If it does eventually land, it means that the timeout wasn't long enough. It's frustrating because it can be impossible to tell which situation you're in.

So it goes:

  • keep checking to see if your transaction was included
  • resend your transaction after some timeout
  • if the blockhash expires, get a new one, resign, and send again

Be sure to read through the entire Solana Cookbook article about this: https://solanacookbook.com/guides/retrying-transactions.html#facts

Jon C
  • 7,019
  • 10
  • 17