【发布时间】:2019-01-07 09:07:09
【问题描述】:
我的 Node.JS dApp 服务器端的 Rinkeby 网络出现间歇性的“替换交易价格过低”错误。我在estimateGas() 调用返回给我的事务 send() 调用中使用了估计气体的确切数量。在我的看涨期权中,我同时添加了gas 和gasLimit 字段,以确保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