Running out of gas error when trying to deploy my solidity smart contract

Hi @romis

Welcome to the forum.

When I attempted to deploy to ganache-cli as is, I received "CrudAEOStructures" ran out of gas. Simply, the contract’s gas requirement is larger than the block gas limit, which (the default) for ganache-cli is 6,721,975.

Compiling in Remix shows the following Gas estimates for your code.

StructuresAndVariables library:

	"Creation": {
		"codeDepositCost": "18000",
		"executionCost": "119",
		"totalCost": "18119"
	}

CrudAEOStructures contract

    "Creation": {
        "codeDepositCost": "5051400",
        "executionCost": "11023",
        "totalCost": "5062423"
    },

In truffle I turned on the optimizer with 200 runs which then allowed me to deploy your contract and library to ganache-cli.

truffle-config.js

  compilers: {
    solc: {
       version: "0.4.23",    // Fetch exact version from solc-bin (default: truffle's version)
      // docker: true,        // Use "0.5.1" you've installed locally with docker (default: false)
      settings: {          // See the solidity docs for advice about optimization and evmVersion
       optimizer: {
         enabled: true,
         runs: 200
       },
       evmVersion: "byzantium"
      }
    }
  }

I would look to see how you could break up your contract and separate out the library.

I suggest reading the OpenZeppelin Guidelines and think about how you might be able to simplify your contracts.

I would also look at the version of compiler you are using, as 0.4.23 was released in April 2018. There was a recent discussion in the forum on What compiler version to use?

Note: I used markdown to improve the display of your code in the forum.

3 Likes