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.

  • 1
    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
  • 1
    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

(Answering myself two year later for those arriving here through Google Airlines):

"new" keyword is the culprit in this case.

Each time "new" is used, the full code of the referenced smart-contract will be included in order to allow to build new SubContract instances at runtime.

If just pre-built references are passed, the compiler is smart-enough to just generate the minimum code to call public methods of the referenced contract.

Your Answer

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

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