To use Relink Protocol from your EVM contract, and let users request Chainlink data, import our contract and call the public functions as shown below.
import "./ChainlinkVRFv2DirectFundingConsumerBase.sol";
contract ChainlinkVRFv2DirectFundingConsumerExample is ChainlinkVRFv2DirectFundingConsumerBase {
using SafeERC20 for IERC20;
// EVENTS
event RandomnessProvided(
bytes32 indexed requestId,
uint256[] indexed randomWords
);
// ERRORS
error RequestAlreadyExists(bytes32 requestId);
error RequestDoesntExist(bytes32 requestId, uint256[] randomWords);
// VARIABLES
mapping(bytes32 => bool) public requestExists;
constructor(
address _proxyContractAddress,
address[] memory permittedOracles,
uint256 threshold
) ChainlinkVRFv2DirectFundingConsumerBase(_proxyContractAddress, permittedOracles, threshold) {
// custom init code
}
function initiateRandomnessRequest() external payable {
bytes32 requestId = requestRandomness(2);
if (requestExists[requestId]) revert RequestAlreadyExists(requestId);
requestExists[requestId] = true;
}
// user implemented
function fulfillRandomWords(bytes32 _requestId, uint256[] memory _randomWords) internal override {
if (!requestExists[_requestId])
revert RequestDoesntExist(_requestId, _randomWords);
emit RandomnessProvided(_requestId, _randomWords);
}
}