I am new to Ethereum dev.
I wrote the code below in my local node to transfer 1 ether between my two Rinkeby testnet.
From account: 0xffD8eb81304291AFcA2C4DA5D26B691b8CC81Bd5
It has 21 ether in Rinkeby (Hope this is sufficient).
// Environment
"web3": "^0.19.1"
Geth
Version: 1.7.2-stable
Git Commit: 1db4ecdc0b9e828ff65777fb466fc7c1d04e0de9
Architecture: amd64
Protocol Versions: [63 62]
Network Id: 1
Go Version: go1.9.2
Operating System: darwin
GOPATH=
GOROOT=/usr/local/Cellar/go/1.9.2/libexec
My nodejs code:
var Web3 = require('web3');
var util = require('ethereumjs-util');
var Tx = require('ethereumjs-tx');
var lightwallet = require('eth-lightwallet');
var txutils = lightwallet.txutils;
var web3 = new Web3(
new Web3.providers.HttpProvider('https://rinkeby.infura.io/qyft9l9yABZ7tJuoX8R4')
//Local RINKEYBY
//new Web3.providers.HttpProvider('http://127.0.0.1:8545')
);
var addr1 = '0xffd8eb81304291afca2c4da5d26b691b8cc81bd5';
var addr2 = '0xba5453837f30b2ba413c06567dd9ea812abf123f';
var privateKey = new Buffer('bf36e0ba1bb26ad4949df0d92554b8702cb595a23410ba8ecac8dbde0d607dfc', 'hex');
var rawTx = {
chainId: web3.toHex('4'),
gas: web3.toHex('21000'),
gasPrice: web3.toHex('25000000000'),
gasLimit: web3.toHex('90000'),
from: '0xffd8eb81304291afca2c4da5d26b691b8cc81bd5',
to: '0xba5453837f30b2ba413c06567dd9ea812abf123f',
value : web3.toHex(web3.toWei(1, "ether"))
}
var tx = new Tx(rawTx);
tx.sign(privateKey);
var serializedTx = tx.serialize();
web3.eth.sendRawTransaction('0x' + serializedTx.toString('hex'), function(err, hash) {
if (!err)
console.log(hash);
else
console.log(err);
});
I always end up with this below error msg :-(
Same happens for me in other private network and mainnet also.
Can you please tell how to get rid of this insufficient funds error.
Error: insufficient funds for gas * price + value at Object.InvalidResponse (/Users/antonyjohnson/Documents/development/angularjs/mean/todo-app/todo-api/node_modules/web3/lib/web3/errors.js:38:16) at /Users/antonyjohnson/Documents/development/angularjs/mean/todo-app/todo-api/node_modules/web3/lib/web3/requestmanager.js:86:36 at XMLHttpRequest.request.onreadystatechange (/Users/antonyjohnson/Documents/development/angularjs/mean/todo-app/todo-api/node_modules/web3/lib/web3/httpprovider.js:118:13) at XMLHttpRequestEventTarget.dispatchEvent (/Users/antonyjohnson/Documents/development/angularjs/mean/todo-app/todo-api/node_modules/xhr2/lib/xhr2.js:64:18) at XMLHttpRequest._setReadyState (/Users/antonyjohnson/Documents/development/angularjs/mean/todo-app/todo-api/node_modules/xhr2/lib/xhr2.js:354:12) at XMLHttpRequest._onHttpResponseEnd (/Users/antonyjohnson/Documents/development/angularjs/mean/todo-app/todo-api/node_modules/xhr2/lib/xhr2.js:509:12) at IncomingMessage. (/Users/antonyjohnson/Documents/development/angularjs/mean/todo-app/todo-api/node_modules/xhr2/lib/xhr2.js:469:24) at emitNone (events.js:111:20) at IncomingMessage.emit (events.js:208:7) at endReadableNT (_stream_readable.js:1056:12)