使用 Solana web3 发送交易时,有时会显示以下错误:
Error: failed to send transaction: Transaction simulation failed: Blockhash not found
除了重试x次之外,处理此错误的正确方法是什么?
有没有办法保证在发送交易时不会发生这个问题?
这是我如何发送交易的示例:
const web3 = require("@solana/web3.js")
const bs58 = require('bs58')
const publicKey = new web3.PublicKey(new Uint8Array(bs58.decode("BASE_58_PUBLIC_KEY").toJSON().data))
const secretKey = new Uint8Array(bs58.decode("BASE_58_SECRET_KEY").toJSON().data)
const connection = new web3.Connection(
"https://api.mainnet-beta.solana.com", "finalized",
{
commitment: "finalized",
confirmTransactionInitialTimeout: 30000
}
)
const transaction = new web3.Transaction().add(
web3.SystemProgram.transfer({
fromPubkey: publicKey,
toPubkey: publicKey,
lamports: 1
})
)
web3.sendAndConfirmTransaction(
connection,
transaction,
[{publicKey: publicKey, secretKey: secretKey}],
{commitment: "finalized"}
)
我该如何改进以避免Blockhash not found
错误?