-1

This question already has an answer here:

I'm looking for the working solution from last 1 week to send payment using this code. But it never works for me and i get following error

Error: Returned error: insufficient funds for gas * price + value

This is my wallet balance to send payment from. I have very small amount of ether in my balance but still it should work to send payment Ether: 7859274664735255 Ether: 0.007859274664735255

Here is my code, Please help me to get it working, it took ages at this point :-(

// 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);

marked as duplicate by Asone, Achala Dissanayake, mirg, Jamie Hale, Lauri Peltonen Mar 26 '18 at 17:37

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

0

Have you tried increasing the gaslimit specified in your code ?

Also, if you do that for testing purposes, you might should try on a testnet first.

  • Can you tell me what Gas limit is supposed to be used as per your directions? I'm on main net and want to go with main only – shawn Mar 26 '18 at 14:01
  • A complete answer has been made to you on the duplicate of your question you've made earlier : ethereum.stackexchange.com/questions/43854/… – Asone Mar 26 '18 at 14:07
  • But that did not work for me, That's i need your help to review code and fix the problem – shawn Mar 26 '18 at 14:17

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