0

I want to confirm a transaction gracefully and wait for it to be finalized. I understand the best way to do this is to use the Connection.confirmTransaction method with the BlockheightBasedTransactionConfirmationStrategy argument reference.

But that method requires 3 things, transaction signature, recent blockhash, and last valid block height. I have the first two, since recent blockhash can be obtained from the Transaction object returned from Connection.getTransaction. But how can I get the last valid block height?

Or is there any other way to handle cases like this and confirm transactions effectively?

1 Answer 1

1

But how can I get the last valid block height?

const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash()

await connection.confirmTransaction({
  blockhash,
  lastValidBlockHeight,
  signature: "your-transaction-signature"
})

You're probably better off using the blockhash from that call rather than the one from the transaction too because it'll be more recent. Docs: https://solana-labs.github.io/solana-web3.js/classes/Connection.html#getLatestBlockhash

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.