2

I have a contract that is exceeding block gas limits (using something like 8000000 gas) when I deploy it. I think it is because it is importing a bunch of other contracts and has functions that create other contracts. Is it possible to reduce gas usage in this scenario? I'm thinking it is compiling all the bytecode from all the imported contracts into the main contract and deploying it all in the transaction.

I suppose one solution is to not create all the contracts from the main contract, but rather initialize with references to the deployed contract addresses. Is there another solution that wouldn't require this type of refactor?

Edit: Just realized my idea of the solution might not work because I still need at least the abstract interfaces for the contract to be deployed with my contract. Not sure how much gas savings that would give me.

  • 1
    Your idea will work. The interface is not deployed as bytecode, it's only used to encode the data in the transaction, hence you would save gas. Other solution is to make factory contracts, instantiate them separately, pass it to your main contract and then call the create method. – ivicaa Mar 1 '18 at 21:01
  • Thanks for that. The factory contract architecture is interesting. In that case I would only need my main contract to have the interface of the factory contract right? – rhlsthrm Mar 1 '18 at 21:48
  • Correct. What you're achieving with this is to reduce the code size of your main contract so it can fit into gas limit. However, in sum, you're paying the same (since you have to deploy the factories). – ivicaa Mar 1 '18 at 21:56
  • Yeah, I would rather have it all in one like how it was structured before, but if I run into these block limit issues I suppose I need to optimize. – rhlsthrm Mar 1 '18 at 22:24

Your Answer

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

Browse other questions tagged or ask your own question.