1
web3.eth.getTransactionCount(addressFrom).then(function(v){
    count = v;
    var amount = web3.utils.toHex(1e16);
    var rawTransaction = {"from":addressFrom, "gasPrice":web3.utils.toHex(20* 1e9),"gasLimit":web3.utils.toHex(210000),"to":contractAddress,"value":"0x0","data":contract.methods.transfer(addressTo, amount).encodeABI(),"nonce":web3.utils.toHex(count)}
    var transaction = new Tx(rawTransaction);
    transaction.sign(privKey);
    web3.eth.sendSignedTransaction('0x'+transaction.serialize().toString('hex'))
    .on('transactionHash',console.log);
});

If I send more than one raw transaction quickly, I get the known transaction error. I got

"UnhandledPromiseRejectionWarning: Error: Returned error: known transaction: 288cd7f1dc2dXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX".

Maybe something is without the 0x, but I don't know how to do that.

2

Most probably this is because when you send two raw transactions quickly, both of your transactions get the same nonce value as you are passing the transaction count of the address as nonce. So in quick sending, transaction count doesn't get updated. Hope it helps!

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.