Skip to content

Instantly share code, notes, and snippets.

@wissalHaji
Last active December 13, 2020 21:03
Show Gist options
  • Save wissalHaji/de697d6a37a3c0b0c96759690bd163f2 to your computer and use it in GitHub Desktop.
Save wissalHaji/de697d6a37a3c0b0c96759690bd163f2 to your computer and use it in GitHub Desktop.
//SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
import './CloneFactory.sol';
contract Factory is CloneFactory {
Child[] public children;
address masterContract;
constructor(address _masterContract){
masterContract = _masterContract;
}
function createChild(uint data) external{
Child child = Child(createClone(masterContract));
child.init(data);
children.push(child);
}
function getChildren() external view returns(Child[] memory){
return children;
}
}
contract Child{
uint public data;
// use this function instead of the constructor
// since creation will be done using createClone() function
function init(uint _data) external {
data = _data;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment