Last active
December 13, 2020 21:03
-
-
Save wissalHaji/de697d6a37a3c0b0c96759690bd163f2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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