Code to reproduce
Environment
Versions Used: Hardhat: 2.10.1, Solidity 0.8.8
Hey guys,
I am building a dapp which requires users to make clones of the implementation contract (I'm using the OpenZeppelin Clones Library). The implementation contracts makes use of Chainlink VRF to generate random numbers, and also makes use of Chainlink Upkeep to automate parts of the contract.
I would like to know how to set up my initializer function in the implementation contract so that I can use ChainLink VRF with the cloned contracts.
In a regular contract, I would simply set up the VRF Address using the constructor, as shown here:
contract Whoopy is Initializable, VRFConsumerBaseV2, KeeperCompatible {
constructor(
address vrfCoordinatorV2,
bytes32 gasLane,
uint64 subscriptionId,
uint32 callbackGasLimit
) VRFConsumerBaseV2(vrfCoordinatorV2) {
i_vrfCoordinator = VRFCoordinatorV2Interface(vrfCoordinatorV2);
i_gasLane = gasLane;
i_subscriptionId = subscriptionId;
i_callbackGasLimit = callbackGasLimit;
}
However, since I am going to be making clones, the CloneFactory cannot call the constructor, hence I will have to use an initialize function instead. I have set up the initialize function as recommended by OpenZeppelin here, however I am not able to figure out how to set up the VRFConsumerBaseV2 contract in this case.
I am currently doing it this way and it doesn't seem to be working:
function initialize(
address _creator ) public override initializer VRFConsumerBaseV2(vrfCoordinatorV2) { //VRFConsumerBaseV2.initialize(vrfCoordinatorV2);*****
i_vrfCoordinator = VRFCoordinatorV2Interface(vrfCoordinatorV2); }
NOTE: I have edited the VRFConsumerBaseV2 contract by removing the 'constructor' and replacing it with an initialiser function instead as shown here (as advised in the OpenZeppelin docs):
function initialize(address _vrfCoordinator) public virtual onlyInitializing {
vrfCoordinator = _vrfCoordinator;
}
TL;DR: How would I go about setting up the initializer in my implementation contract so that I can use ChainLink VRF in the cloned contracts?