admin管理员组文章数量:1389750
I'm getting intermittent "replacement transaction underpriced" errors on the Rinkeby network on the server side of my Node.JS dApp. I am using the exact amount for estimated gas in my transaction send() call returned to me by the estimateGas()
call. In my call options, I am adding both a gas
and gasLimit
field just to be safe with the estimated gas value returned by estimateGas()
in the options
object. Does anyone know how to fix this?
On an unrelated issue. Much to my dismay, just submitting a transaction through Metamask to the Rinkeby network takes about 16 to 30 seconds. Note, I mean from the time the Metamask extension pops up to the time my client side code regains control. I am not talking about the time it takes to get a transaction confirmed/mined by the network. Having said that, I am beginning to wonder if Metamask does not return control to you until the transaction has been mined. Is that the case?
Here is a code fragment of the code I use to send the transaction to Rinkeby (or whatever network I'm testing on):
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);
});
I'm getting intermittent "replacement transaction underpriced" errors on the Rinkeby network on the server side of my Node.JS dApp. I am using the exact amount for estimated gas in my transaction send() call returned to me by the estimateGas()
call. In my call options, I am adding both a gas
and gasLimit
field just to be safe with the estimated gas value returned by estimateGas()
in the options
object. Does anyone know how to fix this?
On an unrelated issue. Much to my dismay, just submitting a transaction through Metamask to the Rinkeby network takes about 16 to 30 seconds. Note, I mean from the time the Metamask extension pops up to the time my client side code regains control. I am not talking about the time it takes to get a transaction confirmed/mined by the network. Having said that, I am beginning to wonder if Metamask does not return control to you until the transaction has been mined. Is that the case?
Here is a code fragment of the code I use to send the transaction to Rinkeby (or whatever network I'm testing on):
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);
});
Share
Improve this question
edited Jul 31, 2018 at 14:06
Robert Oschler
asked Jul 31, 2018 at 4:21
Robert OschlerRobert Oschler
14.4k19 gold badges103 silver badges241 bronze badges
2
- 1 Maybe the transaction underpriced is because that transaction value is "0x00", also the function on your contract should be "payable". – Eduardo Pereira Commented Jul 31, 2018 at 12:25
- @EduardoPereira It's an awkward error message. The actual issue is a duplicate nonce. – Robert Oschler Commented Jul 31, 2018 at 14:05
1 Answer
Reset to default 5It sounds like you found the cause of your issue from your ment. But, to add clarity for others who see the same issue, the error is not solely because of a duplicate nonce. This error will occur when a transaction is submitted with a nonce that is already used in another pending transaction AND the gas price is the same (or less than) the pending transaction.
You can submit a transaction using the same nonce if you use a higher gas price. Miners will always pick the higher priced transaction for pending work, so this is a way to cancel a pending transaction or resubmit a transaction that is being ignored due to low gas prices.
本文标签:
版权声明:本文标题:javascript - Getting "replacement transaction underpriced" errors when sending Ethereum transactions to the Ri 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744733459a2622183.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论