0

Why creating a contract new RewardCourts() in another contract takes more than ten kilobytes of bytecode in the contract it is called from? (It makes bytecode too big and I can't deploy it!)

What to do to deploy one contract from another?

It is line 142 here:

    function _installCourtWrapper(
        Kernel _dao
    )
        internal returns (CourtWrapper)
    {
        bytes32 _appId = keccak256(abi.encodePacked(apmNamehash("open"), keccak256("reward")));
        bytes memory initializeData = abi.encodeWithSelector(CourtWrapper(0).initialize.selector);
        CourtWrapper _wrapper = CourtWrapper(_installDefaultApp(_dao, _appId, initializeData));
//        _courtContract = new RewardCourts(); // takes too much bytecode
//        if (_courtContract != address(0) && _courtId == 0) {
//            _courtId = _courtContract.createCourt();
//        }
//        _wrapper.setCourt(_courtContract, _courtId);
        return _wrapper;
    }
  • Please post your code in plain text here. No links or images. – goodvibration Feb 9 at 10:06
  • 1
    That's a lot to wade through. The file you linked to doesn't contain new RewardCourts() and has less than 142 lines. Maybe revise that link. Also, please describe what chain you are trying to deploy to. – Rob Hitchens Feb 9 at 10:09
  • @RobHitchens-B9lab I've fixed the link. The code is long, I could not post it here. I am deploying to RPC on localhost. – porton Feb 9 at 10:15
  • Please post ONLY the relevant part then. – goodvibration Feb 9 at 10:16
  • Are you using Remix? – Rob Hitchens Feb 9 at 10:22
1

When you deploy a contract A from another contract C then C has to also include A bytecode.

A couple of alternatives:

  • Use a factory contract F from C that will only deploy A so bytecode from A is included in F.

  • Deploy contract A and make C deploy a delegate proxy that will reference existing contract A for bytecode, EIP 1167.

| improve this answer | |

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.