繁体   English   中英

将以太坊交易发送到Rinkeby网络时遇到“置换交易价格低估”错误?

[英]Getting “replacement transaction underpriced” errors when sending Ethereum transactions to the Rinkeby network?

我在Node.JS dApp的服务器端的Rinkeby网络上遇到间歇性的“置换交易价格低估”错误。 我用我的交易发送用于估计气体的确切数额()调用由还给我estimateGas()调用。 在我的看涨期权中,为了安全起见,我同时添加了一个gasgasLimit字段,并在options对象中由gasLimit estimateGas()返回的估计气体值。 有谁知道如何解决这一问题?

在一个无关的问题上。 令我非常沮丧的是,仅通过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);
});

听起来您是从评论中找到问题的原因。 但是,为使看到相同问题的其他人更清楚,该错误不仅是由于重复的随机数。 当提交的随机数已用于另一项挂起的事务中且天然气价格与挂起的事务相同(或小于)时,将发生此错误。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM