0

Trying to send ether to multiple addresses. For the first address the transaction succeeded but for the rest of the addresses it is showing "transaction underpriced". Below is the code attached. I have tried changing the gas price, but that didn't work.

var ad = ['0x66622d1E25cca28454c2e2b4726c05b27B094f68', '0x2F55E7E8Af52dC91715670e579c64A2a84d21A50', '0xd2a56Eb440725BAf29eE1cfA7899c12Ef1BC642D'];

function newfunction() {
    for (var i = 0; i < ad.length; i++) {
        sendRaw(rawTx);
        var rawTx = {
            nonce: web3.toHex(web3.eth.getTransactionCount(address)),
            gasLimit: web3.toHex(21000),
            gasPrice: web3.eth.gasPrice.toNumber() * 1.40,
            to: ad[i],
            value: web3.toHex(web3.toBigNumber(10000000000000000))
        };
    }
}

Attached is the error error code is attached

  • In nonce value, you are entering the same value all time? – Mahesh Rajput Jan 7 at 6:34
  • @MaheshRajput i am getting the nonce value using "web3.toHex(web3.eth.getTransactionCount(address))". should i add "+i" so that it will increase the nonce value by 1 for each addresses in array?(i tried but again i got the error "transaction underpriced" and my first transaction also didnt succeded this time) – Suman Raj Jan 7 at 6:42
0

You're using the same nonce for every transaction, so only one can succeed. Try incrementing the nonce each time. (Also, I'm not sure why the sendRaw call was above the assignment to rawTx. I moved it below.)

function newfunction() {
  var startingNonce = web3.eth.getTransactionCount(address);
  for (var i = 0; i < ad.length; i++) {
    var rawTx = {
      nonce: startingNonce + i,
      gasLimit: web3.toHex(21000),
      gasPrice: web3.eth.gasPrice.toNumber() * 1.40,
      to: ad[i],
      value: web3.toHex(web3.toBigNumber(10000000000000000))
    };
    sendRaw(rawTx);
  }
}

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

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