You can use the web3 method simulateTransaction
. If the blockhash has expired then this method returns an error indicating that the blockhash has expired.
The blockhash is valid if it is within the last 150 blocks.
Do note though that sendTransaction
will also check that the blockhash is valid for you, so long as the you do not skip the preflight checks, skipPreflight: false
, which is one of the sendOptions
in the sendTransaction
method. More on that from the cookbook here
The solana cookbook also goes into more detail here on keeping the transaction fresh. It references an RPC method that isn't yet available on the web3 library specifically for the purpose of checking a blockhash is still valid, called isBlockhashValid.
findReferrence()
to check if a transaction is successful, but i also want to check if a block has passed before a user is able to sign/the user has left the site and the transaction will never be completed so i want to invalidate the transaction