Matt Lally
Matt Lally

Reputation: 435

Setting gas for truffle

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.

Upvotes: 5

Views: 12231

Answers (5)

Barrard
Barrard

Reputation: 2053

To increase the gas limit in Truffle. which truffle to get location of Truffle Open in code editor. code /home/user/.nvm/versions/node/v8.11.1/bin/truffle currently the limit was set at 6721975so i just searched for this number crtl+f 6721975 Change it to 8000000 or whatever.
now in truffle develop web3.eth.getBlock('latest') // 8000000

Upvotes: 0

txbluesrock
txbluesrock

Reputation: 19

I was having the same issue and this is how I made it work: In truffle console, find out the gas limit for the last block. Use that number in your truffle.js. In my case gas: 4700036 worked.

truffle(development)> web3.eth.getBlock('latest').gasLimit

4700036

Upvotes: 1

Neha Kumari
Neha Kumari

Reputation: 787

I also faced the similar issue. The version of truffle I was using was Truffle v4.0.1 (core: 4.0.1). If you downgrade to beta version things will work just fine.

  1. npm uninstall -g truffle
  2. truffle version(to check if its uninstalled)
  3. npm install -g truffle@beta

You are good to go. This should fix the problem.

Upvotes: 1

peyo
peyo

Reputation: 451

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

Upvotes: 2

Matt Lally
Matt Lally

Reputation: 435

This randomly started working the following day. One thing I noticed was that when I ran web3.eth.getBlock("latest") in truffle console yesterday, I was getting gasLimit: 5000, which was a way lower number than the network was reporting elsewhere. Today I was getting gasLimit: 6706583. I'm really not sure what caused the gas limit to increase locally, but whatever it was seems to have fixed the issue.

Upvotes: 1

Related Questions