Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

insufficient funds for gas * price + value #1021

Closed
win2win opened this issue Sep 6, 2017 · 16 comments · Fixed by #2580
Closed

insufficient funds for gas * price + value #1021

win2win opened this issue Sep 6, 2017 · 16 comments · Fixed by #2580
Assignees
Labels
Bug Addressing a bug

Comments

@win2win
Copy link

win2win commented Sep 6, 2017

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. (/home/bogdan/node_modules/web3/packages/web3-providers-http/node_modules/xhr2/lib/xhr2.js:469:24)
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)

@sulliwane
Copy link

Try adding "from" field in your rawTx object :

rawTx = {
    from: yourPublicAddr
}

@win2win
Copy link
Author

win2win commented Sep 18, 2017

This doesn't seem to make a difference.

@sulliwane
Copy link

Right. I think that's because your forgot the "chainId" parameter :

rawTx = {
    chainId: 3
}

let me know...

@win2win
Copy link
Author

win2win commented Sep 19, 2017

This didn't make a difference. Btw. why do you need chainId?

@pannous
Copy link

pannous commented Oct 17, 2017

Is there any working example online?

@lionello
Copy link
Contributor

@win2win You now need chainId because it has become part of the signature (since the fork earlier this year. So many, forgot which one.)

@RamParthiban
Copy link

I gave the chain id. It didn't made any difference. Same Error :-(

@Nishkj
Copy link

Nishkj commented Oct 26, 2017

Even i am facing same issue. Code working fine with testrpc but getting gas related error when trying to deploy on Etherium blockchain

@winterjung
Copy link

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.

before

"config": {
          "chainId": 0,
          "homesteadBlock": 0,
          "eip155Block": 0,
          "eip158Block": 0
      },
      ...

after

"config": {
          "chainId": 42, 
          "homesteadBlock": 0,
          "eip155Block": 0,
          "eip158Block": 0
      },
      ...

@hrachbkweb
Copy link

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 ?

@iurimatias
Copy link
Contributor

@hrachbkweb the sender is always the one to pay for the tx gas. There are proposals (e.g ethereum/EIPs#877) around this, but out of the box the sender is the payer.

@hrachbkweb
Copy link

@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

@hrachbkweb
Copy link

@nivida
Copy link
Contributor

nivida commented Mar 12, 2019

@guifel Could you add the JSON-RPC payload object which got send? This will help me to see the actual issue.

@guifel
Copy link

guifel commented Mar 12, 2019

@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"]
}

@nivida nivida added Bug Addressing a bug and removed Needs Clarification Requires additional input labels Mar 12, 2019
@nivida nivida mentioned this issue Mar 26, 2019
12 tasks
@nivida nivida mentioned this issue Mar 28, 2019
12 tasks
@bsc-eth
Copy link

bsc-eth commented Mar 5, 2024

@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

Have you solved it? I also want to implement A to transfer money to B, and then C pays gas, and I have private keys for A and C, or A is a contract that can create multiple wallet addresses. These addresses are used to receive tokens, and C is used as the contract of contract A. The only authority manager, C calls the contract to transfer tokens from the designated wallet and pay GAS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Addressing a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.