I try to send eth from one address to another, but I get an error:Error: Returned error: nonce too low
What could be the problem?
const Web3 = require('web3')
const web3 = new Web3(new Web3.providers.HttpProvider('https://mainnet.infura.io'))
var Tx = require('ethereumjs-tx').Transaction;
var privateKey = Buffer.from('private_key', 'hex');
var rawTx = {
nonce: '0x000',
gasPrice: '0x09184e72a000',
gasLimit: '0x2710',
to: 'to_address',
value: '0x00',
}
var tx = new Tx(rawTx);
tx.sign(privateKey);
var serializedTx = tx.serialize();
web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex'))
.on('receipt', console.log);
Best Answer
A nonce is basically the number of transactions that have been performed from a particular account address. In order to fix the above error:
Replace the nonce value in the rawTx with the above one.
This will get rid of the nonce too low error.