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:
1
//host to initialize the lazyInitCapableElement level
2
var host = "0x........"
3
//plainUri and dynamicUriResolver to initialize the DynamicMetadataCapableElement level
4
var plainUri = "yourUri"
5
var dynamicUriResolver = "0x......."
6
//modelAddress to initialize the Factory level. It is the model contract that your Factory will clone
7
var modelAddress = "0x......"
8
9
//encode all the parameters
10
var data = web3.eth.abi.encodeParameters(["address"], [modelAddress]);
11
data = web3.eth.abi.encodeParameters(["string", "address", "bytes"], [plainUri, dynamicUriResolver, data]);
12
data = web3.eth.abi.encodeParameters(["address", "bytes"], [host, data]);
Copied!
Then, as explained in the previous page, you have to generate the Factory bytecode and pass it to the create function of the FoF:
1
var Factory = await compile('.../.../.../Factory');
2
var FactoryBytecode = new web3.eth.Contract(Factory.abi).deploy({data : Factory.bin, arguments : [data]}).encodeABI();
3
await FactoryOfFactory.methods.create([accounts[1]], ["Factory test"], [[FactoryBytecode]]).send({from : accounts[1]});
Copied!

Custom Factory

If you want to deploy a custom Factory implementing the standard Factory contract, you have to initialize it in the following way:
1
//host to initialize the lazyInitCapableElement level
2
var host = "0x........"
3
//plainUri and dynamicUriResolver to initialize the DynamicMetadataCapableElement level
4
var plainUri = "yourUri"
5
var dynamicUriResolver = "0x......."
6
//modelAddress to initialize the Factory level. It is the model contract that your Factory will clone
7
var modelAddress = "0x......"
8
//your Factory custom parameters to initialize
9
var yourCustomData1 = "test"
10
var yourCustomData2 = "0x..."
11
12
//encode all the parameters
13
var data = web3.eth.abi.encodeParameters(["string", "address"], [yourCustomData1,yourCustomData2]);
14
data = web3.eth.abi.encodeParameters(["address", "bytes"], [modelAddress, data]);
15
data = web3.eth.abi.encodeParameters(["string", "address", "bytes"], [plainUri, dynamicUriResolver, data]);
16
data = web3.eth.abi.encodeParameters(["address", "bytes"], [host, data]);
Copied!
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):
1
//host to initialize the lazyInitCapableElement level
2
var host = "0x........"
3
//plainUri and dynamicUriResolver to initialize the DynamicMetadataCapableElement level
4
var plainUri = "yourUri"
5
var dynamicUriResolver = "0x......."
6
//modelAddress to initialize the Factory level. It is the model contract that your Factory will clone
7
var modelAddress = "0x......"
8
// fee-business model parameters
9
var feePercentageForTransacted
10
var feeReceiver
11
var tokenToTransferOrBurnAddressInCreation
12
var transferOrBurnAmountInCreation
13
var transferOrBurnReceiverInCreation
14
var tokenToTransferOrBurnAddressInApplication
15
var transferOrBurnAmountInApplication
16
var transferOrBurnReceiverInApplication
17
//your Factory custom parameters to initialize
18
var yourCustomData1 = "test"
19
var yourCustomData2 = "0x..."
20
21
var data = web3.eth.abi.encodeParameters(["string", "uint256"], [yourCustomData1, yourCustomData2]);
22
data = web3.eth.abi.encodeParameters(["uint256", "address", "address", "uint256", "address", "address", "uint256", "address", "byes"], [feePercentageForTransacted, feeReceiver, tokenToTransferOrBurnAddressInCreation, transferOrBurnAmountInCreation, transferOrBurnReceiverInCreation, tokenToTransferOrBurnAddressInApplication, transferOrBurnAmountInApplication, transferOrBurnReceiverInApplication, data]);
23
data = web3.eth.abi.encodeParameters(["address", "bytes"], [YourModelAddress, data]);
24
data = web3.eth.abi.encodeParameters(["string", "address", "bytes"], [YourUri, dynamicUriResolverAddress, data]);
25
data = web3.eth.abi.encodeParameters(["address", "bytes"], [hostAddress, data]);
26
27
var Factory = await compile('.../.../impl/ExampleFactory');
28
var FactoryBytecode = new web3.eth.Contract(Factory.abi).deploy({data : Factory.bin, arguments : [data]}).encodeABI();
Copied!
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:
1
var Factory = await compile('.../.../.../Factory');
2
var FactoryBytecode = new web3.eth.Contract(Factory.abi).deploy({data : Factory.bin, arguments : [data]}).encodeABI();
3
await FactoryOfFactory.methods.create([accounts[1]], ["Factory test"], [[FactoryBytecode]]).send({from : accounts[1]});
Copied!