1

In Vyper, there's a built-in function called create_forwarder_to, which

Duplicates a contract’s code and deploys it as a new instance, by means of a DELEGATECALL.

If my understanding is correct, what create_forwarder_to does is:

  • Choose an existing contract instance A.
  • Deploy a new contract B that will behave the same as A by delegatecalling A's functions whenever there's an incoming function call to B.

The size of bytecode of B can be extremely small, since it's not deploying A again but deploying a forwarder contract that utilizes A's bytecode.

Here is an example of a forwarder contract in Uniswap, and you can see how the forwarder contract is deployed in the factory contract of Uniswap. (create_forwarder_to was called create_with_code_of before and got renamed in this release.)

How can I do what create_forwarder_to does with Solidity?

1

1 Answer 1

1

In solidity it doesnt have that builtin function but you can create it with eip1167(i think in vyper they implement this as builtin function instead of let you code it your self which is safer): https://eips.ethereum.org/EIPS/eip-1167. It is implemented in this github you can check out: https://github.com/optionality/clone-factory?files=1

1

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.