Initialize your Factory

Initialize your Factory without a business model

Standard Factory contract

If you want to deploy the standard Factory contract as it is, you have to initialize it in the following way:

//host to initialize the lazyInitCapableElement level
var host = "0x........"
//plainUri and dynamicUriResolver to initialize the DynamicMetadataCapableElement level
var plainUri = "yourUri"
var dynamicUriResolver = "0x......."
//modelAddress to initialize the Factory level. It is the model contract that your Factory will clone
var modelAddress = "0x......"

//encode all the parameters
var data = web3.eth.abi.encodeParameters(["address"], [modelAddress]);
data = web3.eth.abi.encodeParameters(["string", "address", "bytes"], [plainUri, dynamicUriResolver, data]);
data = web3.eth.abi.encodeParameters(["address", "bytes"], [host, data]);

Then, as explained in the previous page, you have to generate the Factory bytecode and pass it to the create function of the FoF:

var Factory = await compile('.../.../.../Factory');
var FactoryBytecode = new web3.eth.Contract(Factory.abi).deploy({data : Factory.bin, arguments : [data]}).encodeABI();
await FactoryOfFactory.methods.create([accounts[1]], ["Factory test"], [[FactoryBytecode]]).send({from : accounts[1]});

Custom Factory

If you want to deploy a custom Factory implementing the standard Factory contract, you have to initialize it in the following way:

//host to initialize the lazyInitCapableElement level
var host = "0x........"
//plainUri and dynamicUriResolver to initialize the DynamicMetadataCapableElement level
var plainUri = "yourUri"
var dynamicUriResolver = "0x......."
//modelAddress to initialize the Factory level. It is the model contract that your Factory will clone
var modelAddress = "0x......"
//your Factory custom parameters to initialize
var yourCustomData1 = "test"
var yourCustomData2 = "0x..."

//encode all the parameters
var data = web3.eth.abi.encodeParameters(["string", "address"], [yourCustomData1,yourCustomData2]);
data = web3.eth.abi.encodeParameters(["address", "bytes"], [modelAddress, data]);
data = web3.eth.abi.encodeParameters(["string", "address", "bytes"], [plainUri, dynamicUriResolver, data]);
data = web3.eth.abi.encodeParameters(["address", "bytes"], [host, data]);

Then, as shown above, you have to generate the Factory bytecode and pass it to the create function of the FoF.

Initialize your Factory with a business model

If you want to deploy a custom Factory with a fee-based business model, the initialization depends on the parameters to initialize in your Factory.

Here is shown as an example a Factory that implements the EthereansFactory abstract utility contract (more info here):

//host to initialize the lazyInitCapableElement level
var host = "0x........"
//plainUri and dynamicUriResolver to initialize the DynamicMetadataCapableElement level
var plainUri = "yourUri"
var dynamicUriResolver = "0x......."
//modelAddress to initialize the Factory level. It is the model contract that your Factory will clone
var modelAddress = "0x......"
// fee-business model parameters
var feePercentageForTransacted
var feeReceiver
var tokenToTransferOrBurnAddressInCreation
var transferOrBurnAmountInCreation
var transferOrBurnReceiverInCreation
var tokenToTransferOrBurnAddressInApplication
var transferOrBurnAmountInApplication
var transferOrBurnReceiverInApplication
//your Factory custom parameters to initialize
var yourCustomData1 = "test"
var yourCustomData2 = "0x..."

var data = web3.eth.abi.encodeParameters(["string", "uint256"], [yourCustomData1, yourCustomData2]);
data = web3.eth.abi.encodeParameters(["uint256", "address", "address", "uint256", "address", "address", "uint256", "address", "byes"], [feePercentageForTransacted, feeReceiver, tokenToTransferOrBurnAddressInCreation, transferOrBurnAmountInCreation, transferOrBurnReceiverInCreation, tokenToTransferOrBurnAddressInApplication, transferOrBurnAmountInApplication, transferOrBurnReceiverInApplication, data]);
data = web3.eth.abi.encodeParameters(["address", "bytes"], [YourModelAddress, data]);
data = web3.eth.abi.encodeParameters(["string", "address", "bytes"], [YourUri, dynamicUriResolverAddress, data]);
data = web3.eth.abi.encodeParameters(["address", "bytes"], [hostAddress, data]);

var Factory = await compile('.../.../impl/ExampleFactory');
var FactoryBytecode = new web3.eth.Contract(Factory.abi).deploy({data : Factory.bin, arguments : [data]}).encodeABI();

Here you can find the explanation of the fee business model parameters.

Then, as explained in the previous page, you have to generate the Factory bytecode and pass it to the create function of the FoF:

var Factory = await compile('.../.../.../Factory');
var FactoryBytecode = new web3.eth.Contract(Factory.abi).deploy({data : Factory.bin, arguments : [data]}).encodeABI();
await FactoryOfFactory.methods.create([accounts[1]], ["Factory test"], [[FactoryBytecode]]).send({from : accounts[1]});

Last updated