I'm attempting to create a website that allows a user to send a payment for a service. In order to send a transaction on behalf of the user, I have them sign the transaction,which is then serialized and sent to the backend for further processing.
Quite occasionally, I receive this preflight error message when using the sendTransaction
rpc method: Transaction simulation failed: Blockhash not found
.
This makes using our service quite unreliable, as maybe even as much as 1/4 of the requests results in this error. How does one avoid this?
Below is how I ask the user to sign the transaction, and serialize the transaction.
const transaction = new Transaction()
transaction.add(instruction) // Assume this is a transfer instruction
const { blockhash } = await connection.getLatestBlockhash("finalized")
transaction.recentBlockhash = blockhash
transaction.feePayer = feePayer // Assume this public key is defined
const signedTransaction = await signTransaction(transaction) // From @solana/wallet-adapter-react
const signature = signedTransaction.serialize()