VRFV2WrapperConsumerBase

Git Source

Inherits: VRFV2WrapperConsumerBaseInterface

Interface for contracts using VRF randomness through the VRF V2 wrapper

PURPOSE

Create VRF V2 requests without the need for subscription management. Rather than creating

and funding a VRF V2 subscription, a user can use this wrapper to create one off requests,

paying up front rather than at fulfillment.

Since the price is determined using the gas price of the request transaction rather than

the fulfillment transaction, the wrapper charges an additional premium on callback gas

usage, in addition to some extra overhead costs associated with the VRFV2Wrapper contract.

USAGE

Calling contracts must inherit from VRFV2WrapperConsumerBase. The consumer must be funded

with enough LINK to make the request, otherwise requests will revert. To request randomness,

call the 'requestRandomness' function with the desired VRF parameters. This function handles

paying for the request based on the current pricing.

Consumers must implement the fullfillRandomWords function, which will be called during

fulfillment with the randomness result.

State Variables

LinkTokenInterface internal immutable LINK;

VRF_V2_WRAPPER

VRFV2WrapperInterface internal immutable VRF_V2_WRAPPER;

Functions

constructor

constructor(address _link, address _vrfV2Wrapper);

Parameters

NameTypeDescription
_linkaddressis the address of LinkToken
_vrfV2Wrapperaddressis the address of the VRFV2Wrapper contract

requestRandomness

Requests randomness from the VRF V2 wrapper.

function requestRandomness(uint32 _callbackGasLimit, uint16 _requestConfirmations, uint32 _numWords)
    internal
    returns (uint256 requestId);

Parameters

NameTypeDescription
_callbackGasLimituint32is the gas limit that should be used when calling the consumer's fulfillRandomWords function.
_requestConfirmationsuint16is the number of confirmations to wait before fulfilling the request. A higher number of confirmations increases security by reducing the likelihood that a chain re-org changes a published randomness outcome.
_numWordsuint32is the number of random words to request.

Returns

NameTypeDescription
requestIduint256is the VRF V2 request ID of the newly created randomness request.

fulfillRandomWords

fulfillRandomWords handles the VRF V2 wrapper response. The consuming contract must

implement it.

function fulfillRandomWords(uint256 _requestId, uint256[] memory _randomWords) internal virtual;

Parameters

NameTypeDescription
_requestIduint256is the VRF V2 request ID.
_randomWordsuint256[]is the randomness result.

rawFulfillRandomWords

function rawFulfillRandomWords(uint256 _requestId, uint256[] memory _randomWords) external override;