I have a contract similar to:

contract Contract01 {
  SubContract _refContract;
   constructor() public {
      refContract = new SubContract();

   function setSubContractRef(SubContract refContract) {
      _refContract = refContract;

When I add the new SubContract() the bytecode increase is "huge" since it looks like the byte code of the SubContract is also increased. This causes the max-contract size to be reached with easy.

I found it's possible to create a SubContract in a different TX and pass the reference to Contract01 in setSubContractRef, but I'm wondering whether there is a simpler way involving fewer steps.

  • What's refContract;)? An eye-blinking input argument? – goodvibration Mar 7 '19 at 16:41
  • @goodvibration Just a type error. Fixed! – earizon Mar 7 '19 at 16:43
  • Deploy SubContract separately, and pass its address to Contract01. In fact, you are already doing it (more or less), so just copy the contents of function setSubContractRef into the constructor, and you're done. – goodvibration Mar 7 '19 at 16:43

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.