VRF (Verifiable Randomness)

Consuming VRF

Similar to public data streams, consumers send a request to the VRF feed smart contract, and wait for it to generate a new VRF with the provided seed.

You can also find examples here: https://github.com/0xJomo/openoracle-examples

/**
 * Request new randomness from another smart contract
 *
 * Network: Holesky
 * Address: 0x12345....abcde
 */
function requestRandomness() {
  vrfFeed = OpenOracleVRFFeed("0x12345....abcde");
  vrfFeed.createNewTask(/* uint64 VRF seed */);
}

/**
 * Reading latest randomness from another smart contract
 *
 * Network: Holesky
 * Address: 0x12345....abcde
 */
function readLatestRandomness() {
  vrfFeed = OpenOracleVRFFeed("0x12345....abcde");
  (int answer) = vrfFeed.latestRoundData();
}
// Request new randomness from Javascript
const addr = "0x12345....abcde"
const vrfFeed = new web3.eth.Contract(OpenOracleVRFFeed, addr)

const vrfSeed = 123456789
const taskData = ethers.utils.solidityPack(["uint64"],[vrfSeed])

vrfFeed.methods
  .createNewTask(taskData)
  .call()
  .then((requestData) => {
    console.log("Request Hash:", requestData[0])
  })
  
// Read latest data fetch from Javascript
const addr = "0x12345....abcde"
const vrfFeed = new web3.eth.Contract(OpenOracleVRFFeed, addr)
vrfFeed.methods
  .latestRoundData()
  .call()
  .then((resultData) => {
    console.log("Result:", BigInt(resultData[0]) % BigInt(2**32))
  }

Smart Contract Addresses

Last updated