Im trying to send a raw transaction using web3 to ropsten testnet and Im getting this error:

replacement transaction underpriced

where sometimes my tx works and sometimes I get this error.

my tx parameters:

const nonce = web3.eth.getTransactionCount(ethereumConfig.contract.account)
const block = web3.eth.getBlock("latest")
const gasLimit = block.gasLimit
const gasPrice = web3.eth.gasPrice.toNumber() * 1.40 

note I'm already adding 40% to gasPrice

  • Try to increase your gas price. Please let me know the result – A.K. Sep 28 '17 at 10:48
  • I'm already increasing 40% – Ernane Luis Sep 29 '17 at 12:54
up vote 17 down vote accepted

I have been running into this issue as well. The network thinks you are trying to replace an existing unmined transaction. There are two ways to avoid this:

  1. Adding a gas price %10 higher than the existing unmined transaction's gas price.
  2. Increase your nonce to one higher than the unmined transaction.

I have also been getting this error:

"Transaction was not mined within 50 blocks, please make sure your transaction was properly send. Be aware that it might still be mined!"

In my case, I think the transaction is getting stuck in limbo somehow. It's not being mined by anyone, but it's not being removed from the pool of unmined transactions. Keep in mind that web3.eth.getTransactionCount(walletAddress) will only give you the last CONFIRMED nonce. So it won't take the unmined ones into account.

  • so if I do 2. option should do: nonce = web3.eth.getTransactionCount() + 1 ? – Ernane Luis Sep 29 '17 at 12:46
  • 3
    it works increasing the nonce! thanks a lot. – Ernane Luis Sep 29 '17 at 13:16
  • I'm having the same problem, not coding but in a transacction I'm trying to send in myetherwallet. I think increasing the nonce will solve it, but how do I do that if I'm sending my transaction through Metamask? – Moisés Briseño Estrello Dec 8 '17 at 8:04
  • So if I have an unmined transaction sitting around, does it ever go away? I don't want to have to mess with the nonce myself! – sudo May 26 at 18:47
  • Why does the network thinks the transaction is new? doesn't it compare the data and see it's different? – shaharsol Jul 2 at 13:59

Define the Goal

Do you want to:

  1. Send a new transaction, after all your previous transactions have completed, or...
  2. Replace a pending (unmined) transaction, with the new raw transaction.

Send a New Transaction

The error message implies that you're trying to replace a pending transaction. That's because the raw transaction you're trying to send has the same nonce as another transaction that you have pending.

Since replacing a transaction is not your goal, simply increase the nonce to be one higher than your last pending transaction. You may need to track this internally, rather than relying on web3.eth.getTransactionCount().

Replace a Pending Transaction

The 10% Minumum

Since your goal is to replace a transaction that is pending, you must try to convince the miners to use your new transaction. To do that, you must use a gas price that is 10% higher* than the gasPrice of the pending transaction.

const gasPrice = web3.eth.gasPrice.toNumber() * 1.40 

note I'm already adding 40% to gasPrice

The quoted code adds 40% to web3.eth.gasPrice. This may not be 10% higher than the pending transaction's gas price. web3.eth.gasPrice may vary over time, and/or you might have set any arbitrary gas price on the pending transaction.

* 10% isn't defined in the protocol, it's just how most nodes & miners implement it.

Determining the Minimum

If you have the hash of the pending transaction, you can determine the required gas price with something like:

replacement_price = web3.eth.getTransaction(pending_txn_hash).gasPrice * 1.101

Note that this is floating point math, which will have rounding errors, so I threw in an extra 10th of a percent to be sure it was over the minimum.

Double check your Gas price. Even I am also setup Gas Price but somehow did applied proper Gas Price as well. One of example below screen shot. enter image description here

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.