1

I am attempting to use Chainlink VRF along with OpenZeppelin's upgradable contracts to generate a random number. In order to use VRF, I must inherit the constructor from VRFV2WrapperConsumerBase. However, constructors cannot be used with upgradable contracts. While my Chainlink VRF code functions properly without proxies, I get an "execution reverted" error whenever I try to make a call which requires VRF, so I guess it must be an issue with VRFV2WrapperConsumerBase and how I implemented it.

Current code:

contract VRFv2DirectFundingConsumer is VRFV2WrapperConsumerBase, Initializable {
    ...

    address public constant linkAddress = 0x779877A7B0D9E8603169DdbD7836e478b4624789;
    address public constant linkWrapper = 0xab18414CD93297B0d12ac29E63Ca20f515b3DB46;

    // Not allowed to inherit a constructor when using proxies
    constructor() VRFV2WrapperConsumerBase(linkAddress, linkWrapper) {
        _disableInitializers();
    }

    function initialize() public payable initializer { 
        admin = msg.sender;
    }

    // Call example
    function requestRandomWords() internal returns (uint256 requestId) {
        requestId = requestRandomness(
            callbackGasLimit,
            requestConfirmations,
            numWords
        );

        return requestId;
    }

1 Answer 1

0
contract Contract is
    Storage,
    ReentrancyGuard,
    UsingDiamondOwner,
    UserManager,
    AutomationCompatibleInterface,
    VRFConsumerBaseV2(0x8103B0A8A00be2DDC778e6e7eaa21791Cd364625) //passing values when it is inherit
{
  //contract logic
}

I tried like this and it worked !

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.