将以太坊交易发送到 Rinkeby 网络时出现“替代交易定价过低”错误?

Rob*_*ler 4 javascript ethereum solidity web3js

我在 Node.JS dApp 的服务器端的 Rinkeby 网络上出现间歇性的“替换交易定价过低”错误。我在调用返回给我的交易 send() 调用中使用了估计 gas 的确切数量estimateGas()。在我的看涨期权,我加入一个都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);
});
Run Code Online (Sandbox Code Playgroud)

Ada*_*nis 5

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

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