Clone the model contract

Once you have deployed and initialized your Factory, it is up and running for users to clone the model contract set.

To clone and initialize the model contract, users have to use the deploy function of the Factory passing the model contract initialization data as deployData:

function deploy(bytes calldata deployData) external payable returns(address deployedAddress, bytes memory deployedLazyInitResponse);

Here you can find some examples of how to create the deployData to pass on.

Model contract implementing LazyInitCapableElement

If the Factory model contract implements LazyInitCapableElement, the deployData is composed as follows:

//host to initialize the lazyInitCapableElement level
var host = "0x........"
//model contract specific parameters to initialize
var yourCustomData1 = "test"
var yourCustomData2 = "0x..."
//encode the parameters
var data = web3.eth.abi.encodeParameters(["string", "address"], [yourCustomData1, yourCustomData2]); 
data = web3.eth.abi.encodeParameters(["address", "bytes"], [host, data]);
  
//Initialize the model contract directly when cloning it by the Factory
var Example = await FactoryContract.methods
  .deploy(data)
  .send({from : accounts[1]});

The Factory deploy function automatically calls the lazyInit function of the model contract initialing it.

Model contract implementing DynamicMetadataCapableElement

If the Factory model contract implements DynamicMetadataCapableElement, the deployData is composed as follows:

//host to initialize the lazyInitCapableElement level
var host = "0x........"
//plainUri and dynamicUriResolver to initialize the DynamicMetadataCapableElement level
var singletonUri = "..."
var dynamicUriResolverAddress = "0x..."
//model contract specific parameters to initialize
var yourCustomData1 = "test"
var yourCustomData2 = "0x..."
//encode the parameters
var data = web3.eth.abi.encodeParameters(["string", "address"], [yourCustomData1, yourCustomData2]);
data = web3.eth.abi.encodeParameters(["string", "address", "bytes"], [singletonUri, dynamicUriResolverAddress, data]);
data = web3.eth.abi.encodeParameters(["address", "bytes"], [host, data]);
  
//Initialize the model contract directly when cloning it by the Factory
var Example = await FactoryContract.methods
  .deploy(data)
  .send({from : accounts[1]});

The Factory deploy function automatically calls the lazyInit function of the model contract initialing it.

Last updated