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.
function requestRandomWords() public {
uint numWords = 2;
uint numConfirmations = 3;
vrfId = _vrfOracle.requestRandomness(numWords, numConfirmations);
}
function getRandomWords() public view returns (uint[] memory randomWords) {
randomWords = _vrfOracle.getRandomness(vrfId);
}
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.14;
// *************************************
// * Minimum Viable VRF Oracle *
// *************************************
// This contract shows how to get up and running as quickly as posible with Chainlink's VRF oracle
// We will requestRandomness from the oracle and fetch it later
import "datum-contracts/interfaces/VRFv2Interface.sol";
contract VRFOracleTest {
VRFOracleV2 _vrfOracle =
VRFOracleV2(0x48749fde6370FBfc9a45C5EFB559253D72B7Cd53);
uint vrfId;
// Submit a random uint request to the Oracle
function requestRandomWords() public {
uint numWords = 2;
uint numConfirmations = 3;
vrfId = _vrfOracle.requestRandomness(numWords, numConfirmations);
}
// Fetch the random uint back
function getRandomWords() public view returns (uint[] memory randomWords) {
randomWords = _vrfOracle.getRandomness(vrfId);
}
}