1

I do need to deploy a lot of similar smart contracts. With Solidity it's quite easy, but expensive :(

I'm doing:

contract One {
 ...
}

contract Builder {
    function create(uint8 amount) public returns (address[]) {
        uint8 i = 0;
        address[] contracts;
        while (i++ < amount) {
           address[i] = new One();
        }
        return contracts;
    }
}

This approach works, but costs almost same amount of gas as it would creating via separate transactions. It looks like that EVM is just cloning code into new place in storage and we have anyway pay for gas for such duplicated code.

Is there any way to have pointers in new accounts into place in storage where code is stored instead of duplicating same bytecode into own storage?

1
  • 1
    You could write your contract in a fashion that instead of redeploying the whole thing, proxy contracts can use just one instance of the code Commented Jul 23, 2018 at 1:57

1 Answer 1

1

Checkout the library clone-factory. Basically you create one master contract that has all the logic of the contracts you want to deploy, and when you deploy each clone contract, they're actually just proxies that delegatecall the master contract. It adds a little bit extra to each call, but saves immensely on contract code gas costs.

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.