EVM / Solidity

Smart Contracts

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.

Note: to always get the most up to date information about the library, please see the README of the repo here: https://github.com/RelinkServices/relink-contracts-solidity-evm

Attention: The following code is for showcase purposes only and is not production ready.

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);
    }
}

Last updated