LazyInitCapableElement
How It Works
LazyInitCapableElement
is an abstract contract that your model contract must integrate in order for your contract to be Factory clonable.
It provides:
The
constructor
, which can be used if your contract is deployed and initialized manually (i.e, not via a Factory)The
lazyInit
function, which is automatically called when your contract is cloned from a Factory
The lazyInit
function internally calls the empty virtual _lazyInit
function, which your model contract can override in order to manage and initialize its specific custom data.
Host
The LazyInitCapableElement
provides an host
address parameters which can be used in your model contract to build custom permission logics.
How to Code a Factory-Compliant Smart Contract
Your model contract must integrate LazyInitCapableElement
as follows:
And at the interface level, if any, as follows:
Through this integration, your contract acquires all LazyInitCapableElement
capabilities.
You also need to insert the constructor
into your smart contract. This allows you to deploy the contract even without a Factory, and to initialize it in the โtraditionalโ way.
Coded like this, the constructor
calls the LazyInitCapableElement
constructor
and thus can use all logic of the lazyinitCapableElement
, such as that which allows it to execute lazyInitData
.
After integrating the constructor
, you need to override _lazyInit
โs virtual function, which manages data initialization of your model contract.
In the example below, _lazyInit
initializes three parameters: callerPercentage
, lastSplitBlock
and splitInterval
.
Of course, if your model contract doesnโt have any additional data to initialize, the _lazyInit
override function doesnโt have to be included.
Now you have a contract that is Factory-compliant. It can be cloned via a factory, and then initialized either via that factory or (if it was manually deployed) via the traditional constructor
method.
Initialize the model contract
Here, you learn how to clone and initialize the model contract using a Factory.
Last updated