【问题标题】:Getting "replacement transaction underpriced" errors when sending Ethereum transactions to the Rinkeby network?将以太坊交易发送到 Rinkeby 网络时出现“替换交易价格过低”错误?
【发布时间】:2019-01-07 09:07:09
【问题描述】:

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

关于一个不相关的问题。 令我沮丧的是,仅通过 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);
});

【问题讨论】:

  • 也许交易被低估是因为交易价值是“0x00”,你的合约上的功能也应该是“payable”。
  • @EduardoPereira 这是一个尴尬的错误消息。实际问题是重复的随机数。

标签: javascript ethereum solidity web3js


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2022-01-25
    • 1970-01-01
    • 2019-05-23
    • 1970-01-01
    • 2021-09-23
    • 2021-11-25
    • 2020-03-15
    • 2021-10-02
    • 2019-12-09
    相关资源
    最近更新 更多