I have lots of Ether in the account and have tried various accounts.
When I run this code below against testrpc, it completes successfully, but once I switch to my private geth or ropsten, this error shows consistently.
My version of geth is 1.6.7
I use Ubuntu 16.04.
This below is the code portion of the code which I'm running taken from the web3 examples
`var Web3 = require('web3');
var web3 = new Web3(
new Web3.providers.HttpProvider('http://localhost:8545/')
);
var key="xxx"
var Tx = require('ethereumjs-tx');
var privateKey = new Buffer(key, 'hex')
var bytecode ="6060604052341561000c57fe5b5b60a68061001b6000396000f30060606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806339ec021c14603a575bfe5b3415604157fe5b6058600480803560ff16906020019091905050605a565b005b6000600082600a0a60ff16629896800262ffffff1691508190505b5050505600a165627a7a723058201aa083f84301acc104a3de0151822aa682702844181a821c16490689e05d729e0029";
var rawTx = {
nonce: "0x2",
gasLimit: "0x2DC6C0",
gasPrice: "0x4A817C800",
value: '0x00',
data: '0x' + bytecode
};
var tx = new Tx(rawTx);
tx.sign(privateKey);
var serializedTx = tx.serialize();
web3.eth.sendSignedTransaction( "0x" + serializedTx.toString('hex'))
.on('receipt', console.log);
`
Error shows like this.
Unhandled rejection Error: Returned error: insufficient funds for gas * price + value
at Object.ErrorResponse (/home/bogdan/node_modules/web3/packages/web3-core-helpers/src/errors.js:29:16)
at /home/bogdan/node_modules/web3/packages/web3-core-requestmanager/src/index.js:137:36
at XMLHttpRequest.request.onreadystatechange (/home/bogdan/node_modules/web3/packages/web3-providers-http/src/index.js:64:13)
at XMLHttpRequestEventTarget.dispatchEvent (/home/bogdan/node_modules/web3/packages/web3-providers-http/node_modules/xhr2/lib/xhr2.js:64:18)
at XMLHttpRequest._setReadyState (/home/bogdan/node_modules/web3/packages/web3-providers-http/node_modules/xhr2/lib/xhr2.js:354:12)
at XMLHttpRequest._onHttpResponseEnd (/home/bogdan/node_modules/web3/packages/web3-providers-http/node_modules/xhr2/lib/xhr2.js:509:12)
at IncomingMessage.
at emitNone (events.js:91:20)
at IncomingMessage.emit (events.js:188:7)
at endReadableNT (_stream_readable.js:975:12)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickCallback (internal/process/next_tick.js:104:9)
Try adding "from" field in your rawTx object :
rawTx = {
from: yourPublicAddr
}
This doesn't seem to make a difference.
Right. I think that's because your forgot the "chainId" parameter :
rawTx = {
chainId: 3
}
let me know...
This didn't make a difference. Btw. why do you need chainId?
Is there _any_ working example online?
@win2win You now need chainId because it has become part of the signature (since the fork earlier this year. So many, forgot which one.)
I gave the chain id. It didn't made any difference. Same Error :-(
Even i am facing same issue. Code working fine with testrpc but getting gas related error when trying to deploy on Etherium blockchain
In my case, I changed config in genesis.json and solved insufficient funds for gas * price + value problem. It works fine when I set chainId to any other number except zero number.
"config": {
"chainId": 0,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
...
"config": {
"chainId": 42,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
...
how I can specify the account which will pay for gas
let say x1 is sending tokens to x2 but I want x3 (I have private key) to pay for tx gas ?
@hrachbkweb the sender is always the one to pay for the tx gas. There are proposals (e.g https://github.com/ethereum/EIPs/pull/877) around this, but out of the box the sender is the payer.
@iurimatias thanks for response .Is there any way to overcome this ?
Obviously all users can't have ether but they want to buy/sell tokens
@guifel Could you add the JSON-RPC payload object which got send? This will help me to see the actual issue.
@nivida The failed transaction with beta 48:
{
jsonrpc: "2.0",
id: 6,
method: "eth_sendRawTransaction",
params: ["0xf86306843b9aca0082753094829bd824b016326a401d083b33d092293333a83064802ca08df5134f7c64b68bbca694e265a27533575344b9f5c2d3fc3afeb9960fa31681a01a45264f134534c2b7b6258d7a4d77a58c335fdcef85d3b0241949c67b9a7fde"]
}
Note that I am not seeing the issue with beta 37. This is the successful transaction I get with it:
{
jsonrpc: "2.0",
id: 4,
method: "eth_sendRawTransaction",
params: ["0xf86309843b9aca0082753094829bd824b016326a401d083b33d092293333a83064802ca068a8301b65fb14004def54e97a8b91e7db22b5765dbde3c8a9434b5c686ff4d3a064c3a318097e0ecdb32a945569c844551cfab5ee538bd7a6e202616d0dabc970"]
}
Most helpful comment
This didn't make a difference. Btw. why do you need chainId?