0

I've seen some example's, where the contract deploys other contract (e.g. this one), but is it possible to do so using binary of the contract? something like:

function deployContract(bytes contractsBin) { ... }

As far as I know there is no way to send transaction via contract, so RPC way is not an option.

1

Of course you can, you just have to rely on solidity assembly to do it.

Check out the create / create2 opcodes:

  • create(v, p, s) - create new contract with code mem[p..(p+s)) and send v wei and return the new address
  • create2(v, n, p, s) - create new contract with code mem[p..(p+s)) at address keccak256( . n . keccak256(mem[p..(p+s))) and send v wei and return the new address

You can even go ahead and save gas by "cloning" and existing contract. An example implementation can be found at: https://gist.github.com/holiman/069de8d056a531575d2b786df3345665

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.