I have been searching around and reading the documents of the sway language, but I realize there is a missing of contract creation, such instructions have been heavily used in solidity smart contract programming, e.g [Uniswap V2 Factory Contract] β deploy β [Pool Contract]
All transactions on Fuel are either Script or ContractCreate transactions. Thus, a script can not create a contract.
This is a deliberate design choice, as this is a mechanism that is not needed in the FuelVM. Since contract IDs (addresses) are deterministic by design, there is no need for a CREATE2 style opcode. In addition, the βdynamicβ creation of contracts has implications for the efficiency of fraud proofs over transaction execution, which is a further reason for its exclusion.
The primary design goal for a factory pattern can be achieved on Fuel by specifying a bytecode root which an implementation must match. For example, equivalent functionality to the snippet provided can be found in our implementation of a Uniswap v2-style AMM, where exchange contracts are registered with the central AMM contract using this mechanism.
Thank you so much for your rapid reply and knowledgeable feedback. I still have some questions about the needing for CREATE2 style opcode. Not sure if I understand it correctly:
tx on Fuel is either Script or ContractCreate, meaning a contract address cannot send a tx for ContractCreate ?
In terms of the needing for the feature, the contract address is deterministic however I think for a lot of applications, there is still a need for decentralized created a child contract from a factory contract such as a multisig wallet, the implementation in AMM makes a single tx for CREATE2 into a deploy + register pool (2tx) seems not too user-friendly