ChainlinkVRF
Inherits: IChainlinkVRF
Title: ChainlinkVRF
Authors: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80), Modified from Chainlink (https://github.com/smartcontractkit/chainlink-evm/blob/develop/contracts/src/v0.8/vrf/VRFConsumerBaseV2Plus.sol)
Diamond facet for Chainlink VRF V2.5 subscription-funded random words.
Stateless delegator — all logic and storage live in ChainlinkVRFLib.
This facet handles the request/track layer only. Consumer facets that
inherit this contract should override rawFulfillRandomWords to act on
delivered randomness after calling super.rawFulfillRandomWords.
Notes:
- lattice-version: 0.1.0
- lattice-source: Chainlink
Functions
getConfig
Returns the current VRF configuration.
function getConfig() external view virtual override 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 virtual override 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 virtual override;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
virtual
override
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 virtual override;Parameters
| Name | Type | Description |
|---|---|---|
| requestId | uint256 | The coordinator-assigned request ID. |
| randomWords | uint256[] | The generated random words. |
exportSelectors
ERC-8153 selector export: this facet's cuttable selectors, tightly packed (4 bytes each).
Excludes exportSelectors() itself (0x0ef22643) - it is never cut into a diamond. Order matches
forge inspect ChainlinkVRF methodIdentifiers (alphabetical by signature); kept in exact parity by
ExportSelectorsParityTest. Chunks:
getConfig() 0xc3f909d4
getUserKey(uint256) 0xdd1e2651
rawFulfillRandomWords(uint256,uint256[]) 0x1fe543e3
requestRandomWords(bytes32,uint32) 0x5eff05e5
setConfig((address,uint256,bytes32,uint16,uint32)) 0xb289a570
function exportSelectors() external pure virtual returns (bytes memory selectors);Returns
| Name | Type | Description |
|---|---|---|
| selectors | bytes |