[Ethereum] Error from sendSignedTransaction: Error: Returned error: replacement transaction underpriced

contract-deploymentgo-ethereummistsolidity

I am the beginner in Ethereum stuff need guidance please help
I am running a private ethereum network and using mist wallet
here is my contract code

pragma solidity ^0.4.0;

contract MyFirstContract {
    uint256 counter =0;

    function increase() public {
        counter++;
    }

    function  decrease() public{
        counter--;
    }

    function getCounter() public constant  returns (uint256) {
        return counter;
    }
}

the counter value was not changing when I press execute increment or decrement function counter value was not changing after many tries i got these error message
I am getting the error message "Error from sendSignedTransaction: Error: Returned error: replacement transaction underpriced"after some researching I found out this answer
error: replacement transaction underpriced
I have one pending transaction

web3.eth.pendingTransactions();

[{
    blockHash: null,
    blockNumber: null,
    from: "0x4f7f384236f79a5e3322e33cc7bb2ccd5143a87c",
    gas: 188189,
    gasPrice: 18000000000,
    hash: "0x193d30297d98ad9da5958e6295d61bf333050cec901601ccdbf83e9c0b1cb082",
    input: "0x60806040526000805534801561001457600080fd5b5060ea806100236000396000f30060806040526004361060525763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166313bdfacd81146057578063d732d95514607b578063e8927fbc14608f575b600080fd5b348015606257600080fd5b50606960a1565b60408051918252519081900360200190f35b348015608657600080fd5b50608d60a7565b005b348015609a57600080fd5b50608d60b3565b60005490565b60008054600019019055565b6000805460010190555600a165627a7a7230582094d5704152e41ee1cb7ab5b820a49845ec5652e2c9c442a8d55da756f6d5cda60029",
    nonce: 10,
    r: "0x34fa67311a0a29d31139a425c2ab120033d4ab34a6d1a860d6c806f95412f7af",
    s: "0x7d831f773e541f73a2371be911ec29b36d803db414ab4712007c4b00d4f10be9",
    to: null,
    transactionIndex: 0,
    v: "0x1b",
    value: 0
}]

so I increased the nounce
web3.eth.getTransactionCount("0x4f7f384236f79a5e3322e33cc7bb2ccd5143a87c")+1;
11

after then I again try to exceute the transaction but again getting these messages
enter image description here

Best Answer

Nonces are 0 indexed, transactions are indexed from 1. This post here mentions:

Apparently there's a nuance with the nonce... my error was I was setting the nonce to web3.eth.getTransactionCount() + 1, which left a gap between prior transaction nonce and next transaction nonce (nonces are 0 indexed, transactions are indexed from 1, that's the root of the error). It so appears that you are not allowed to increment the nonce by 2 and leave a gap. Must be sequential.

Requested instructions: You need to find out the nonce value of the first transaction you fire.

var firstNonce = web3.eth.getTransactionCount(yourSender);.

The post I linked above and here shows how to set nonce manually(and a common error, that getTransactionCount already returns a value one higher than the nonce and was the reason for my answer)

Related Topic