向 Rinkeby 网络发送以太坊交易时遇到"replacement transaction underpriced"错误?



我的Node.JS dApp服务器端的Rinkeby网络上出现间歇性的"替换事务定价过低"错误。在estimateGas()调用返回给我的transaction send((调用中,我使用的是估计天然气的确切数量。在我的调用选项中,我添加了gasgasLimit字段,只是为了安全起见,estimateGas()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。当提交的交易具有已在另一个未决交易中使用的随机数,并且天然气价格与未决交易相同(或小于(时,将发生此错误。

如果你使用更高的天然气价格,你可以使用相同的随机数提交交易。矿工总是会为未决工作选择价格较高的交易,因此这是一种取消未决交易或重新提交因天然气价格低而被忽略的交易的方法。

相关内容

最新更新