我在创建签名时收到错误消息
Error:
TransactionExpiredBlockheightExceededError: Signature 2XqzFuyv5YWpDPTT87CVu48QJPemGSu5rbCazrNBgY6D3mS8rugKugtzXDGpN6XZF8FPyWwXQvzfm4ZyMx6gTf6j has expired: block height exceeded.
这样创建的签名:
const transaction = program.methods(...)
transaction.feePayer = publicKey;
transaction.recentBlockhash = (await connection.getLatestBlockhash()).blockhash;
const latestBlockHash = await connection.getLatestBlockhash()
// ----> Phantom recommended way of signing tx
const { signature } = await provider.signAndSendTransaction(transaction);
const confirmation = await connection.confirmTransaction(
{
blockhash: latestBlockHash.blockhash,
lastValidBlockHeight: latestBlockHash.lastValidBlockHeight,
signature,
}
);
几秒/分钟或 2 秒后,尽管 TX 已确认并最终确定,但我收到上述错误消息。
如何处理?如果tx被添加到区块中,为什么会弹出错误?
事务失败是一种棘手的情况,而 web3.js 目前在弄清楚发生了什么方面做得并不好。
此错误具体意味着交易是使用区块哈希进行签名的,该区块哈希(通常)不会包含在任何新区块中。如果您发现区块哈希值太旧,则需要获取新的区块哈希值,重新签署交易,然后再次发送。
但是,在此之前,您可以尝试重新发送之前的交易。可能是它被发送给一个不包含它的领导者,然后由于某种原因没有转发给另一个领导者。
如果它最终落地,则意味着超时时间不够长。这很令人沮丧,因为无法判断您处于哪种情况。
事情就是这样:
请务必阅读有关此内容的整篇 Solana Cookbook 文章:https://solanacookbook.com/guides/retrying-transactions.html#facts
您能找到解决此错误的方法吗?我也遇到同样的事情