0

I am sending ether to an array of addresses. I am getting the nonce value from eth_getTransactionCount. But problem is that the first transaction is successful but for the rest of the transactions are not because the value of nonce is same as of first.

below is the code

 function signTransaction($t, $v, $d = '0x', $mt1 = "latest", $addr = '0x') {
    global $user_details;

    if($addr == '0x') {
        $user_address = $user_details['address'];
    } else {
        $user_address = $addr;
    }

    $dt = [$user_address, $mt1];
    $nonce = infuraReq('eth_getTransactionCount', $dt, 'bchexdec');

    $dt = [ 
        'nonce' => $nonce, 
        'from' => $user_address,
        'to' => $t,
        'amount' => $v,
        'data' => $d,
        'privkey' => privateKey()
    ];

    $rData = [
        'rawdata' => $dt,
        'signed' => web3Req('signtransaction', $dt, 'POST') 
    ];
    return $rData;
}

How do I solve this issue? Note: I cannot keep on changing the gas value as number of addresses are very high.

  • You can just increment the nonce for each transaction you send. – smarx Jan 5 at 10:50
  • @smarx sir, already tried but not working – Suman Raj Jan 5 at 10:51
  • If you're having trouble, please share the version of your code that increases the nonce properly. – smarx Jan 5 at 10:57
  • @smarx i just changed "'nonce' => $nonce" to "'nonce' => $nonce+1".. is it wrong? – Suman Raj Jan 5 at 10:59
  • Yes, that's wrong. That would still use the same (incorrect) nonce for each transaction. – smarx Jan 5 at 11:00

Your Answer

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

Browse other questions tagged or ask your own question.