IChainlinkVRF
Title: IChainlinkVRF
Author: Modified from Chainlink (https://github.com/smartcontractkit/chainlink-evm/blob/develop/contracts/src/v0.8/vrf/VRFConsumerBaseV2Plus.sol)
Interface for the ChainlinkVRF Diamond facet.
This module handles request tracking for Chainlink VRF V2.5
(subscription-funded). The rawFulfillRandomWords entry point is called
by the coordinator and manages bookkeeping only; consumer facets that
inherit ChainlinkVRF should override it to act on the randomness.
Functions
getConfig
Returns the current VRF configuration.
function getConfig() external view returns (VRFConfig memory);Returns
| Name | Type | Description |
|---|---|---|
| <none> | VRFConfig |
getUserKey
Returns the user key associated with a pending VRF request.
function getUserKey(uint256 vrfRequestId) external view returns (bytes32);Parameters
| Name | Type | Description |
|---|---|---|
| vrfRequestId | uint256 | The coordinator-assigned request ID. |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bytes32 | The user-supplied key, or bytes32(0) if not found. |
setConfig
Sets or replaces the VRF configuration.
Caller must hold DEFAULT_ADMIN_ROLE.
Reverts VRFInvalidConfig if coordinator is zero, subscriptionId is
zero, or keyHash is zero.
function setConfig(VRFConfig calldata config) external;Parameters
| Name | Type | Description |
|---|---|---|
| config | VRFConfig | The new VRF configuration. |
requestRandomWords
Requests random words from the VRF coordinator.
Caller must hold DEFAULT_ADMIN_ROLE.
Stores the userKey against the returned vrfRequestId so the
fulfilment callback can look it up.
function requestRandomWords(bytes32 userKey, uint32 numWords) external returns (uint256 vrfRequestId);Parameters
| Name | Type | Description |
|---|---|---|
| userKey | bytes32 | Arbitrary key the caller wants associated with this request. |
| numWords | uint32 | Number of random words to request. |
Returns
| Name | Type | Description |
|---|---|---|
| vrfRequestId | uint256 | The coordinator-assigned request ID. |
rawFulfillRandomWords
Called by the VRF coordinator to deliver random words.
Verifies the caller is the configured coordinator, looks up the user key,
clears the pending entry, and emits RandomWordsFulfilled.
Consumer facets should override this function to consume the randomness.
function rawFulfillRandomWords(uint256 requestId, uint256[] calldata randomWords) external;Parameters
| Name | Type | Description |
|---|---|---|
| requestId | uint256 | The coordinator-assigned request ID. |
| randomWords | uint256[] | The generated random words. |
Events
VRFConfigSet
Emitted when the VRF configuration is updated.
event VRFConfigSet(address coordinator, uint256 subscriptionId, bytes32 keyHash);Parameters
| Name | Type | Description |
|---|---|---|
| coordinator | address | Address of the VRF coordinator. |
| subscriptionId | uint256 | Subscription ID funding the requests. |
| keyHash | bytes32 | Key hash identifying the oracle's VRF public key. |
RandomWordsRequested
Emitted when random words are requested from the coordinator.
event RandomWordsRequested(uint256 indexed vrfRequestId, bytes32 indexed userKey, uint32 numWords);Parameters
| Name | Type | Description |
|---|---|---|
| vrfRequestId | uint256 | The coordinator-assigned request ID. |
| userKey | bytes32 | The caller-supplied key associated with this request. |
| numWords | uint32 | The number of random words requested. |
RandomWordsFulfilled
Emitted when the coordinator fulfils a request.
event RandomWordsFulfilled(uint256 indexed vrfRequestId, bytes32 indexed userKey);Parameters
| Name | Type | Description |
|---|---|---|
| vrfRequestId | uint256 | The coordinator-assigned request ID. |
| userKey | bytes32 | The caller-supplied key originally associated with this request. |
Errors
VRFNotConfigured
VRF has not been configured (coordinator address is zero).
error VRFNotConfigured();VRFOnlyCoordinator
rawFulfillRandomWords was called by an address other than the coordinator.
error VRFOnlyCoordinator(address caller);Parameters
| Name | Type | Description |
|---|---|---|
| caller | address | The unauthorised caller. |
VRFRequestNotFound
The given VRF request ID has no pending entry.
error VRFRequestNotFound(uint256 vrfRequestId);Parameters
| Name | Type | Description |
|---|---|---|
| vrfRequestId | uint256 | The unknown request ID. |
VRFInvalidConfig
setConfig was called with an invalid configuration (zero coordinator,
zero subscription ID, or zero key hash).
error VRFInvalidConfig();VRFInvalidUserKey
requestRandomWords was called with a zero userKey.
bytes32(0) is the sentinel used by rawFulfillRandomWords to
detect a missing pending request. Allowing a zero userKey would make
the fulfillment callback indistinguishable from an unknown request ID.
error VRFInvalidUserKey();Structs
VRFConfig
Full VRF subscription configuration.
struct VRFConfig {
/// @notice Address of the VRF coordinator.
address coordinator;
/// @notice Subscription ID funding requests.
uint256 subscriptionId;
/// @notice Key hash identifying the oracle's VRF public key.
bytes32 keyHash;
/// @notice Minimum confirmations before the oracle responds.
uint16 requestConfirmations;
/// @notice Gas limit for the fulfillment callback.
uint32 callbackGasLimit;
}Properties
| Name | Type | Description |
|---|---|---|
| coordinator | address | |
| subscriptionId | uint256 | |
| keyHash | bytes32 | |
| requestConfirmations | uint16 | |
| callbackGasLimit | uint32 |