1

I am trying to deploy a contract on ropsten network that requires ~7000000 gas, however the current gas limits are ~3.5mil on ropsten and I am unable to deploy the contract. What can I do about this?

2 Answers 2

1

Could you share your contract code so we can try to see what's causing the high deployment cost?

There may or may not be an easy solution to this problem. You should check how much gas is being spent on the size of your compiled contract code, and how much is being spent on executing the contructor function.

Try to reduce the size of your contract by:

  • Compiling it with optimization enabled

  • Manually optimizing your code for size. Remove duplicate code, and remove code that is not strictly necessary. If some function is only needed client-side, remove it from the contract and implement it client-side.

  • Splitting functionality into multiple contracts

Try to reduce the gas cost of your constructor function by:

  • Reducing the size and amount of constants (e.g. array literals, string literals)

  • Reducing the amount of writes to storage. Every storage slot of 256 bits costs 20000 gas, so setting a uint256 costs 20000, setting a 64 character string costs 60000.

  • Limit the amount of calls to functions in other contracts

  • If there are loops in your constructor function, try to limit the amount of iterations

  • Generally limit the amount of work performed in the constructor function

1
  • "Limit the amount of calls to functions in other contracts". I have a question: Is calling functions in other contracts more expensive? I would think that offloading some of the functions to other contracts would help him decrease contract size and thus lower the deployment cost.
    – Sky
    Commented Aug 2, 2022 at 9:41
1

Use a different testnet! At the time of this writing, the latest blocks in each testnet had a block gas limit of:

  1. Rinkeby: 10 million (see block)
  2. Kovan: 12.5 million (see block)
  3. Goerli: 30 million (see block)

Otherwise you can also always try and reduce the contract size, see here.

1
  • Yes, I switched my testing network, however before the limit was 8 million on Ropsten but guess this will have to do Commented Sep 29, 2020 at 16:42

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.