OpenLayer
  • Introduction
    • About OpenLayer
    • Our Mission
    • Our Approach
      • Foundations
        • OpenNodes
        • Restaking
        • Validation services
          • What is OVC
          • How is it done
          • Why is it better
        • Infrastructure
      • Modular Design
        • Modular data source
        • Modular source of security
        • Modular validation
        • Modular data transformation
        • Modular interoperability
      • Lifecycle of a Request
  • Data Validation Light Paper
  • OpenLayer AVS
    • Why Data Layer
    • How OpenLayer Works
    • Crypto Security
      • Websession proofs
      • Parser execution
    • End User Participation
    • On Demand Security
    • Multi Token Staking
    • Zero Bridging Solutions
  • For Node Operators
  • For Developers
    • Public Data Streams
    • VRF (Verifiable Randomness)
    • User Personal Data Proving
  • Privacy Policy
Powered by GitBook
On this page
  • Consuming VRF
  • Smart Contract Addresses
  1. For Developers

VRF (Verifiable Randomness)

PreviousPublic Data StreamsNextUser Personal Data Proving

Last updated 9 months ago

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:

/**
 * 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

Network
Address

Holesky (17000)

0x298e55eDe8AE5fD1Ec68DFce867D6D77b4EEA8c5

Plume Testnet (161221135)

0xaDeb194Edf918C76a32a7Eb3E5cCcDed08F786B1

Camp Testnet V2 (325000)

0x2ea329336246e89BFF5bB87E6dCc74EBe9d2b039

https://github.com/0xJomo/openoracle-examples