gpt4 book ai didi

javascript - 将以太坊交易发送到 Rinkeby 网络时出现 "replacement transaction underpriced"错误?

转载 作者:行者123 更新时间:2023-11-29 10:28:49 33 4
gpt4 key购买 nike

我在 Node.JS dApp 服务器端的 Rinkeby 网络上遇到间歇性的“替换交易定价过低”错误。我在通过 estimateGas() 调用返回给我的交易 send() 调用中使用了估计气体的确切数量。在我的看涨期权中,我同时添加了 gasgasLimit 字段,只是为了确保 estimateGas() 返回的估计 gas 值安全options 对象。有谁知道如何解决这个问题?

关于一个不相关的问题。令我沮丧的是,仅通过 Metamask 向 Rinkeby 网络提交交易大约需要 16 到 30 秒。请注意,我的意思是从 Metamask 扩展弹出到我的客户端代码重新获得控制权。我不是在谈论通过网络确认/挖掘交易所需的时间。话虽如此,我开始怀疑 Metamask 是否在交易被挖掘之前不会将控制权交还给你。是这样吗?

这是我用来将交易发送到 Rinkeby(或我正在测试的任何网络)的代码片段:

contractMethodToCall.estimateGas(
{ from: publicAddr, gasPrice: 20000000000, gas: 1500000})
.then(function(estimatedGas) {
if (estimatedGas <= 0)
throw new Error("The estimated gas for the transaction is zero.");

const rawTx = {
nonce: fromNonce,
gasPrice: gasPriceGwei,
// Use the estimated gas.
gasLimit: estimatedGas,
// Adding both gas and gasLimit just in case.
gas: estimatedGas,
to: contractAddr,
value: '0x00',
data: encodedAbiForCall
}

let tx = new Tx(rawTx);

// Sign the transaction using our server private key in Buffer format.
tx.sign(privateKeyBuffer);

let serializedTx = '0x' + tx.serialize().toString('hex');

return web3.eth.sendSignedTransaction(serializedTx);
});

最佳答案

听起来您从评论中找到了问题的原因。但是,为了让看到相同问题的其他人更加清楚,错误不仅仅是因为重复的 nonce。当提交的交易带有已在另一笔待处理交易中使用的随机数,并且汽油价格与(或低于)待处理交易相同时,将发生此错误。

如果您使用更高的汽油价格,您可以使用相同的随机数提交交易。矿工总是会为待处理的工作选择价格较高的交易,因此这是一种取消待处理交易或重新提交因低 gas 价格而被忽略的交易的方法。

关于javascript - 将以太坊交易发送到 Rinkeby 网络时出现 "replacement transaction underpriced"错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51605416/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com