5

Try to send a transaction using phantom wallet and vuejs.

  import { createUpdateMetadataAccountV2Instruction } from '@metaplex-foundation/mpl-token-metadata';
  import { Transaction } from '@solana/web3.js';

  const updateMetadataAccount = createUpdateMetadataAccountV2Instruction(
    accounts,
    args
  );

  const transaction = new Transaction();
  transaction.add(updateMetadataAccount);
  const { blockhash } = await connection.getLatestBlockhash();
  console.log(blockhash) // "G6NXXgYaPYjpg4StqSMywYb582Rwzsc3pYXWKJbRcNoA"
  transaction.recentBlockhash = blockhash;
  transaction.feePayer = wallet.publicKey;
  const signature = await wallet.signAndSendTransaction(transaction)

I got this error: RPC Error: failed to send transaction: Transaction simulation failed: Blockhash not found

2 Answers 2

7

A call to connection.getLatestBlockhash() will retrieve a blockhash from the RPC node you have configured in connection, at the commitment level in connection. This blockhash is then used in the transaction that is forwarded to the leader when you send the transaction.

There are two cases that can cause a Blockhash not found error:

  1. The retrieved blockhash ended up being on a minority fork of the network and the leader does not consider it valid - or the RPC node later drops it as a minority fork. Avoid this by using getLatestBlockhash('finalized'), which will give you a blockhash that has been finalized by the network.

-or-

  1. Enough time has passed between your call to getLatestBlockhash() and sending the transaction that the network has moved on and the blockhash is now too old. Avoid this by only retrieving the blockhash when it's time to send.

Here is a lot more words on the subject of transaction confirmation: https://jstarry.notion.site/Transaction-confirmation-d5b8f4e09b9c4a70a1f263f82307d7ce

1
  • 2
    There's a third thing to add to this answer: if you fetch the blockhash from a network (eg. devnet) that doesn't match the network the transaction is being sent on (eg. mainnet) then the RPC will also report that the blockhash could not be found. Dec 9, 2022 at 19:47
2

I think is worth mentioning because is such a common mistake, that you will also see this error when a web3 app is connected to Mainnet but the network of your Phantom wallet is switched to Devnet (or the other way around)

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.