Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nodeError("replacement transaction underpriced") #42

Closed
cctanfujun opened this issue Sep 20, 2018 · 18 comments
Closed

nodeError("replacement transaction underpriced") #42

cctanfujun opened this issue Sep 20, 2018 · 18 comments

Comments

@cctanfujun
Copy link

i call a contract method twice in a short time,and create this error,i know this is beacuse of the same nonce,but i don't know how to solve it, i need call the method twice,make two transcation.Anyone can help?

@shamatar
Copy link
Contributor

@cctanfujun what you can do is to supply the parameter onBlock:”pending” when you send two transactions in sequence. This will cause the internal transaction counter to include transactions that are in the queue to be included in the nonce counter, so you will send two transactions with nonce and nonce+1 in sequence.

Sent with GitHawk

@cctanfujun
Copy link
Author

@cctanfujun what you can do is to supply the parameter onBlock:”pending” when you send two transactions in sequence. This will cause the internal transaction counter to include transactions that are in the queue to be included in the nonce counter, so you will send two transactions with nonce and nonce+1 in sequence.

Sent with GitHawk

but i saw the source code,onBlock default value is pending?

@shamatar
Copy link
Contributor

Hm, in this case I suggest a to use a workflow that I’ve posted in a previous question from you. Looks like the node (do you use Infura?) does not include the transaction in a mempool instantly and still provides you with the same nonce

Sent with GitHawk

@cctanfujun
Copy link
Author

Hm, in this case I suggest a to use a workflow that I’ve posted in a previous question from you. Looks like the node (do you use Infura?) does not include the transaction in a mempool instantly and still provides you with the same nonce

Sent with GitHawk

yes i used infura

@cctanfujun
Copy link
Author

could you please give an example?

this is my code?

let contract_address = EthereumAddress("0x921d631877e4989f66ee1cc13a9c20f9fd2ab3c4")!
        let checkin_contract = web3Rinkeby.contract(jsonstr, at: contract_address, abiVersion: 2)!
        let gasPriceResult = web3Rinkeby.eth.getGasPrice()
        guard case .success(let gasPrice) = gasPriceResult else {
            return
        }
        var options = Web3Options.defaultOptions()
        options.from = sender
        let parameters = [] as [AnyObject]
        let intermediate = checkin_contract.method("sign_in", parameters: parameters, options: options)!
        let gasEstimateResult = intermediate.estimateGas(options: nil)
        guard case .success(let gasEstimate) = gasEstimateResult else {
            return
        }
        let result = intermediate.send(password: "BANKEXFOUNDATION", options: options)
        switch result {
        case .success(let res):
            print("check in successful")
            print(res)
        case .failure(let error):
            print(error)
        }

i call this twicce in a short time, and got the error?
really thanks!

@frankynines
Copy link

Im getting this error as well and cannot resolve.
When I increase the gas to force a success, the transaction never gets mined. It also weirdly shows up on etherscan as a "Secondary Node" tx. Which fails after an hour or 2.

I've tried several times to adjust nonce and gas/// whats going on here?

@cctanfujun
Copy link
Author

Im getting this error as well and cannot resolve.
When I increase the gas to force a success, the transaction never gets mined. It also weirdly shows up on etherscan as a "Secondary Node" tx. Which fails after an hour or 2.

I've tried several times to adjust nonce and gas/// whats going on here?

hello,this is because nonce should be set sequence,when you send a nonce is 1 transcation ,and then you send a same nonce transcation will cause this error, because of when use infura transcation maybe not include in memory ,you will get this error.so you can set nonce manual,use
assemble

@shamatar
Copy link
Contributor

shamatar commented Sep 30, 2018 via email

@frankynines
Copy link

frankynines commented Sep 30, 2018

I've done both of these. Setting nonce higher, as well as Increasing the gas.
What happens is the transaction is getting picked-up by Rinkeby on a "secondary node"

screen shot 2018-09-28 at 11 46 21 am

And in return ends up failing.

@frankynines
Copy link

frankynines commented Sep 30, 2018

screen shot 2018-09-30 at 7 54 01 am

Here is the entire method, with assemble added.

screen shot 2018-09-30 at 7 49 50 am

Note this worked Last week, until I updated my pods.

@shamatar
Copy link
Contributor

shamatar commented Sep 30, 2018 via email

@frankynines
Copy link

frankynines commented Oct 1, 2018

Gotcha, I'll try again tomorrow.

Ideally, I just want any transaction to Mine. I must have old ones that are stuck, I cant figure it out.

Old transactions can fail thats fine, if Kicking them from the Mem Pool is the only way to get a new transaction to mine, then yes. I need to kick the pending Nonce.

From your note is the pattern to...
Send with Fail due to old transaction
then
Assemble and increase nonce.
then
Send New Transaction
?

@shamatar
Copy link
Contributor

shamatar commented Oct 1, 2018 via email

@BaldyAsh
Copy link
Collaborator

@cctanfujun @FrankyAguilar
Do you have any questions?

@frankynines
Copy link

This still doesn't work. Same issue, still happening.

@skywinder
Copy link
Collaborator

@FrankyAguilar Am I right understand, that you want to have the transactions queue locally to be able send\push\pop transactions from this queue and want to be sure, that all of them will be posted in infura with confliction each other?

@BaldyAsh
Copy link
Collaborator

BaldyAsh commented Mar 6, 2019

@FrankyAguilar, @cctanfujun hi, I've finally got this bug in live. Also got node error "nonce too low".
Solution worked for me:

  1. Send transaction with highest nonce and automatic gasPrice and gasLimit (or set them manually).
    Get highest nonce you can trying something like that:
guard let pendingNonce = try self.web3Instance?.eth.getTransactionCount(address: EthereumAddress(self.address)!, onBlock: "pending") else {
    throw Errors.NetworkErrors.cantCreateRequest
}
guard let latestNonce = try self.web3Instance?.eth.getTransactionCount(address: EthereumAddress(self.address)!, onBlock: "latest") else {
    throw Errors.NetworkErrors.cantCreateRequest
}
let selectedNonce = max(pendingNonce, latestNonce)
  1. Get gasPrice from transaction result (if you set it automatically)
  2. If you got "replacement transaction underpriced" then increase gas price by %10 and send transaction again
  3. If you got "nonce too low" then increase it by 1 and send transaction again

Hope it will help you

@BaldyAsh
Copy link
Collaborator

Closed due to inactivity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants