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

NetworkAddress

Holesky (17000)

0x298e55eDe8AE5fD1Ec68DFce867D6D77b4EEA8c5

Plume Testnet (161221135)

0xaDeb194Edf918C76a32a7Eb3E5cCcDed08F786B1

Camp Testnet V2 (325000)

0x2ea329336246e89BFF5bB87E6dCc74EBe9d2b039

Last updated