1

I'm trying to clone a Lottery contract which contains Chainlink VRF Coordinator address as part of the contructor. This is the constructor of the main contract which I'd like to clone:

    constructor(
    address vrfCoordinatorV2, //contract
    // uint256 entranceFee,
    bytes32 gasLane,
    uint64 subscriptionId,
    uint32 callbackGasLimit
) VRFConsumerBaseV2(vrfCoordinatorV2) {
    // i_entranceFee = entranceFee;
    i_vrfCoordinator = VRFCoordinatorV2Interface(vrfCoordinatorV2);
    i_gasLane = gasLane;
    i_subscriptionId = subscriptionId;
    i_callbackGasLimit = callbackGasLimit;
    s_raffleState = RaffleState.CLOSED;
    s_lastTimeStamp = block.timestamp;
    contractOwner = payable(msg.sender);
}

Here is the code for my 'Clone' contract for which I am getting an error:

    pragma solidity ^0.8.8;

    import './Raffle.sol';
import '@openzeppelin/contracts/access/Ownable.sol';
import "@openzeppelin/contracts/proxy/Clones.sol";
import "@chainlink/contracts/src/v0.8/interfaces/VRFCoordinatorV2Interface.sol";
import "@chainlink/contracts/src/v0.8/VRFConsumerBaseV2.sol";
import "@chainlink/contracts/src/v0.8/KeeperCompatible.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";





contract RaffleFactory is Clones {
    Raffle[] public raffleArray;
    address public raffleImplementation;

    function createRaffle() public {
        address clone = Clones.clone(raffleImplementation);
        Raffle(clone).initialize(address vrfCoordinatorV2, bytes32 gasLane, uint64 subscriptionId, uint32 callbackGasLimit);
        return clone;
        raffleArray.push(clone);
    }
} 

The error seems to be with initialising the vrfCoordinatorV2 address. I would like to create a clone factory contract which others can use to clone cheap instances of my main contract.

Any help would be appreciated. Thanks in advance!

1
  • Can you post the error you are seeing? For one you should not return clone; before raffleArray.push(clone); and your method has no return value defined
    – Milk
    Aug 29, 2022 at 22:41

1 Answer 1

1

Hello ethereumboy

You need to define the data for all of these parameters:

  • address vrfCoordinatorV2
  • bytes32 gasLane (or keyHash)
  • uint64 subscriptionId
  • uint32 callbackGasLimit

Take a look on this example extracted from the VRF documentation


  // Goerli coordinator. For other networks,
  // see https://docs.chain.link/docs/vrf-contracts/#configurations
  address vrfCoordinator = 0x2Ca8E0C643bDe4C2E08ab1fA0da3401AdAD7734D;

  // The gas lane to use, which specifies the maximum gas price to bump to.
  // For a list of available gas lanes on each network,
  // see https://docs.chain.link/docs/vrf-contracts/#configurations
  bytes32 keyHash = 0x79d3d8832d904592c0bf9818b621522c988bb8b0c05cdc3b15aea1b6e8db0c15;

  // Depends on the number of requested values that you want sent to the
  // fulfillRandomWords() function. Storing each word costs about 20,000 gas,
  // so 100,000 is a safe default for this example contract. Test and adjust
  // this limit based on the network that you select, the size of the request,
  // and the processing of the callback request in the fulfillRandomWords()
  // function.
  uint32 callbackGasLimit = 100000;

In order to use VRF, you need to create or already have a subscriptionId

Like was explained in subscriptions

You are creating a Raffle Factory, so for each raffle that you create, you need to add it to your subscription, programmatically

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.