5

Truffle v4 used to deploy the contract successfully, but Truffle v5 truffle migrate command fails.

My process to deploy:

1) delete buidl/ folder

2) truffle compile

3) truffle migrate

Truffle v5

The error I get is:

Error:  *** Deployment Failed ***
"ContractName" ran out of gas. Something in the constructor (ex: infinite loop) 
caused gas estimation to fail. Try:
* Making your contract constructor more efficient
* Setting the gas manually in your config or as a deployment parameter
* Using the solc optimizer settings in 'truffle.js'
* Setting a higher network block limit if you are on a
 private network or test client (like ganache).

at C:\Users\dziug\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\truffle-deployer\src\deployment.js:364:1
at process._tickCallback (internal/process/next_tick.js:68:7)
Truffle v5.0.0 (core: 5.0.0)
Node v10.4.0

My truffle-config.js looks like this:

module.exports = {
  networks: {
    development: {
      host: 'localhost',
      port: 8545,
      network_id: '*',
  compilers: {
    solc: { 
      version: "^0.4.24",
      optimizer: {
        enabled: true,
        runs: 200
      }
    }
  }

Then I installed truffle v4 and tried to migrate the same contract:

1) npm uninstall -g truffle

2) npm install -g [email protected]

3) delete buidl/ folder

4) truffle compile

5) truffle migrate

And it works. I can deploy it on the rinkeby too.

Remix doesn't deploy it with

javascript VM: "creation of ContractName errored: transaction execution failed"

However, I can deploy it to Rinkeby through Remix

I need this contract to be deployed with truffle v5, because I will develop Solidity 0.5.* contracts that will communicate with the one I am trying to deploy right now, otherwise I won't be able to test with javascript.

The contract I am trying to deploy is: https://github.com/cryptocopycats/awesome-cryptokitties/tree/master/contracts

with couple fixes and additions. Contract starts from KittyCore.sol

1

4 Answers 4

8

Check @goodvibration answer. It should work in most instances.

I don't recommend the answer that I will share below, it will ignore the EIP-170, hopefully there is a better answer

I was only able to make it migrate using: ganache-cli --gasLimit=0x1fffffffffffff --allowUnlimitedContractSize -e 1000000000

--allowUnlimitedContractSize: "Allows unlimited contract sizes while debugging. By enabling this flag, the check within the EVM for contract size limit of 24KB (see EIP-170) is bypassed. Enabling this flag will cause ganache-cli to behave differently than production environments."

-e {number}: gives that much ether to all 10 accounts

My truffle-config.js looks like this:

module.exports = {
  networks: {
    development: {
      host: 'localhost',
      port: 8545,
      network_id: '*',
      gas: 0x1fffffffffffff
    },
  }
}
2
  • Cheers! It worked Jun 30, 2019 at 13:48
  • How to do the same with Ganache UI ?
    – Surya
    Jun 18, 2021 at 19:14
0

Your truffle-config.js file is not correct. Have a look at: https://github.com/trufflesuite/truffle/releases/tag/v5.0.0-beta.0#bring-your-own-compiler

For the correct format for the truffle-config.js file.

2
  • 1
    Instead of saying that the config file is not correct, it would be way more useful if you pointed out what is wrong with it, and provide a fix, instead of referring to a fairly broad documentation where it's hard to figure out what's wrong with it.
    – lacabra
    Jan 29, 2019 at 3:55
  • I didn't mean to be unhelpful, your truffle-config.js file doesn't seem to be correct. I was just speaking plainly. The documentation is the best place to check, and the correct format is right at the top. Specifically: It's not a valid javascript object for one thing (6 open curly braces, 3 close curly braces) and it should have a format like this: module.exports = { networks: { ... etc ... }, compilers: { solc: { version: <string> // ex: "0.4.20". (Default: Truffle's installed solc) } } }; Jan 30, 2019 at 19:09
0

I think the problem is in your config:

module.exports = {
  networks: {
    development: {
      host: 'localhost',
      port: 8545,
      network_id: '*',
  compilers: {
    solc: { 
      version: "^0.4.24", // this line
      optimizer: {
        enabled: true,
        runs: 200
      }
    }
  }

If you want to use v5, you have to change to appropriate solc version, like 0.5.0

1
  • This is incorrect. That's the Solidity version which is a different thing than the Truffle version.
    – Ryan
    Jun 2, 2021 at 12:53
0

On Ganache, set Gas Limit as 8721975 and in Truffle config, set the gas as 8721974

   development: {
     host: "127.0.0.1",     // Localhost (default: none)
     port: 7545,            // Standard Ethereum port (default: none)
     network_id: "*",       // Any network (default: none)
     gas: 8721974
    },

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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