VRF Oracle V2

Get Random numbers from Chainlink's Oracle on Chain

Chainlink VRF (Verifiable Random Function) is a provably fair and verifiable random number generator (RNG) that enables smart contracts to access random values without compromising security or usability. For each request, Chainlink VRF generates one or more random values and cryptographic proof of how those values were determined. The proof is published and verified on-chain before any consuming applications can use it. This process ensures that results cannot be tampered with or manipulated by any single entity including oracle operators, miners, users, or smart contract developers.

This guide explains how to get random values using a simple contract to request and receive random values from Chainlink VRF v2

We Support Direct Funding method currently , but there is no Fees currently applied to the Client , they are paid by the DATUM Oracle Consumer contract . We will add the functionality in future.

Using VRF v2

  • Start by importing the datum-contracts package

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.14;

import "datum-contracts/interfaces/OptimisticOracleV3Interface.sol";
  • Create the contracts instance with the VRF Oracle address

  // For Sepolia
  oracleAddress = 0x48749fde6370FBfc9a45C5EFB559253D72B7Cd53

VRFOracleV2 _vrfOracle =
        VRFOracleV2(oracleAddress);
  • Next step it to request the Random numbers from contract with the numWords and Numconfirmations info , from Oracle using requestRandomness

  • The process will take place in backend and will probably take about 2-3 Minutes , so be patient

  • To get the Random Words from the Oracle , call getRandomness

Full Example Contract Code

Last updated