I am working with Ganache and Truffle. I am trying to deploy kind of a huge smart contract, but most of the functions in this smart contract are pre-prod functions, so I do not really worry about real-world migration.

Therefore, I am trying to deploy my smart contract with ganache locally without wanting to worry about gas usage. No matter what I have tried, I still get the error:

"SmartContractName" ran out of gas (using a value you set in your network config or deployment parameters.)

I've been playing with Ganache block-limit and gas price: ganache-cli -g 0 -l 1000000000000 I've been playing with the gas in the migration file return deployer.deploy(SmartContractName, { gas: 400000000000 })

And I've been playing with truffle-config:

development: {
    host: "localhost",
    port: 8545,
    network_id: "*",
    gas: 1000000000,
    gasPrice: 0

So far, nothing has worked. Does anyone have a solution?


With seeing the code it is impossible to confirm this, but I suspect your code contains an endless loop, or possibly just one that loops an unreasonable number of times.

Unbounded for loops and recursion are anti-patterns. See this: https://blog.b9lab.com/getting-loopy-with-solidity-1d51794622ad

From your question, I think you understand that it is rather pointless to build anything with a gas requirement that will ever exceed the network gasLimit (currently around 8 million) and you are correctly setting it higher for your dev network with -l n.

It's been raised absurdly high already, which is why I think no upper limit will be enough. Time to figure out why the contract starts a journey from which it will never return. If this were regular computer and gasLimit didn't put a stop to it, I think you would have to kill the process somehow.

Hope it helps.

  • Hi, thanks for your answer! Actually I already checked that my entire code works: unit tests are working with no issue and a 100% code coverage, and if I comment any function, the migration works. The issue really seems to be coming from the size of the smart contract, and ganache and truffle tweaking options do not seem to work :/ – Thanh-Quy Nguyen May 17 at 15:40
  • I dont understand what you mean by testing if you are unable to deploy it. If you can clarify that, it might help pinpoint the issue. Keep in that many internal errors can present as out of gas because the EVM will burn all gas to force a revert. This can lead to misleading messages. – Rob Hitchens - B9lab May 17 at 16:33
  • Well I can test a few functions pack by pack if I comment the other functions. It just seems the smart contract is too long for truffle to deploy it. Is there a list of error that could present themselves as out of gas? – Thanh-Quy Nguyen May 18 at 15:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.