Im using this code to send payment from Address A to address B.. But im getting this error always.
(node:18492) UnhandledPromiseRejectionWarning: Error: Returned error: insufficient funds for gas * price + value
I read at many places it may be fixed if chainId is changed. I changed many chainId but it did not work for me. I always get error :-(
// Require the web3 node module.
var Web3 = require('web3');
var Tx = require('ethereumjs-tx');
// Show Web3 where it needs to look for a connection to Ethereum.
//web3 = new Web3(new Web3.providers.HttpProvider('http://127.0.0.1:8545'));
web3 = new Web3(new Web3.providers.HttpProvider('https://mainnet.infura.io/N6IIa2HvDYOovtgmPbhD'));
var gasPrice = '25000000000';//or get with web3.eth.gasPrice
var gasLimit = '9000';
var addr = '0x.................................';
var toAddress = '0x.................................';
var amountToSend = "1859274664735255";
var nonce = web3.eth.getTransactionCount(addr); //211;
var rawTransaction = {
"from": addr,
"nonce": web3.utils.toHex(nonce),
"gas": web3.utils.toHex('21000'),
"gasPrice": web3.utils.toHex(gasPrice),
"gasLimit": web3.utils.toHex(gasLimit),
"to": toAddress,
"value": web3.utils.toHex(amountToSend) ,
"chainId": web3.utils.toHex('1')
};
var privateKey = '......................................................';
var privKey = new Buffer(privateKey, 'hex');
console.log("privKey : ", privKey);
const tx = new Tx(rawTransaction);
tx.sign(privKey);
const serializedTx = `0x${tx.serialize().toString('hex')}`;
web3.eth.sendSignedTransaction(serializedTx);
var amountToSend = "0.00192823123348952"; //$1
Ether: 7859274664735255
And and change my code tovar amountToSend = "1859274664735255";
But still i get same error