Setting gas for truffle

Matt Lally picture Matt Lally · Aug 10, 2017 · Viewed 7.4k times · Source

I'm running truffle migrate on main. Also using geth. I originally left gas price and gas empty in truffle.js, but now it looks like this:

live: {
  network_id: 1,
  host: "127.0.0.1",
  port: 8545,
  from: "3984bc76cb775d7866d1cd55c4f49e3d13d411d4",
  gas: 40000,
  gasPrice: 22000000000 // Specified in Wei
}

I seem to have a situation where I either have too much gas or not enough, with no possibility for the right amount.

 <   {
 <     "jsonrpc": "2.0",
 <     "id": 2,
 <     "error": {
 <       "code": -32000,
 <       "message": "insufficient funds for gas * price + value"
 <     }
 <   }
Error encountered, bailing. Network state unknown. Review successful transactions manually.
Error: insufficient funds for gas * price + value

...or...

 <   {
 <     "jsonrpc": "2.0",
 <     "id": 2,
 <     "error": {
 <       "code": -32000,
 <       "message": "exceeds block gas limit"
 <     }
 <   }
Error encountered, bailing. Network state unknown. Review successful transactions manually.
Error: exceeds block gas limit

When I run web3.eth.getBlock("latest") in console, I get gasLimit: 5000. When I set my gas at 5000 I get the insufficient funds message. When I set it to 5001, I get "exceeds block gas limit".

So, all this seems to be telling me that the gasLimit should be set to 5000 or under 5000, but in that case I don't have sufficient funds to run the transaction. Let's see...

I have:

gas: 5000, gasPrice: 22000000000 // Specified in Wei

5000 * 22000000000 = 1.1 * 10^14 = 110,000,000,000,000 Wei 1.1 * 10^14 / 10 ^ 18 (number of Wei in 1 Ether) = 1.1*10^-4 ETH

Here's the account I'm using: https://etherscan.io/address/0x3984bc76cb775d7866d1cd55c4f49e3d13d411d4. As you can see, it has funds. 0.01738465 Ether at time of writing, to be precise.

Answer

peyo picture peyo · Aug 14, 2017

if you are on a test network, on testrpc, the option -l or --gasLimit lets you set the gas available.

On geth, this post should help : https://ethereum.stackexchange.com/questions/13730/how-to-increase-gas-limit-in-block-using-geth