DIA Nexus Documentation
  • Nexus Overview
  • Intro to Nexus
    • How it works
    • Nexus vs. Lumina
    • Integrated Chains
  • Data products
    • Token Price Feeds
    • RWA Price Feeds
    • Randomness
    • Fair-value Feeds
  • How-to Guides
    • Fetch Price Data
      • Solidity
      • Vyper
      • Demo Oracles
      • Chain-specific Guide
        • Aleph Zero
        • Alephium
        • Edu Chain
        • Hydration
        • Kadena
        • LUKSO
        • Somnia
        • Stacks
        • Superseed
        • XRP Ledger (XRPL)
    • Generate Randomness
      • Solidity
      • WASM
      • Demo Oracles
      • Chain-specific Guide
        • Alephium
    • Migrate to DIA
    • Fund the Oracle
    • Build a Scraper
      • Development Cluster Stack
      • DIA Test‐Space with Docker Compose
      • DIA Test‐Space with Minikube
      • Add a new exchange scraper
      • Add a new foreign scraper
      • Add a new liquidity scraper
      • Additional notes
  • Request a Custom Oracle
  • Reference
    • Architecture
      • Data sourcing
      • Data computation
      • Data delivery
    • APIs
      • Token prices
        • RestAPI
          • Request Samples
        • GraphQL
          • Request Samples
      • RWA prices
    • Pricing Methodologies
      • IR: Interquartile Range Filter
      • MAIR: Moving Average with Interquartile Range Filter
      • VWAP: Volume Weighted Average Price
      • VWAPIR: Volume Weighted Average Price with Interquartile Range Filter
      • LST fair price
    • Data Sources
      • CEXes Data
      • DEXes Data
    • Smart Contracts
      • DIAOracleV2.sol
      • DIARandomOracle.sol
    • Randomness Protocol
  • Resources
    • Audits
    • Community & Support
    • Security Bounty Program
    • Research
      • Return Rates in Crypto Farming
      • Crypto Volatility Index
      • Compounded Rates
      • Polkadot Medianizer
    • T&C
      • Licence Agreement
      • Contributor Covenant Code of Conduct
      • Disclaimer
Powered by GitBook
On this page
  • Oracle details
  • Oracle configuration
  • How to access data
  • Support
Export as PDF
  1. How-to Guides
  2. Generate Randomness
  3. Chain-specific Guide

Alephium

dApps built on Alephium can leverage DIA oracles to consume verifiable & decentralized random numbers on-chain, generated by the drand protocol.

PreviousChain-specific GuideNextMigrate to DIA

Last updated 1 month ago

Oracle details

Chain
Address

Alephium Mainnet

Alephium Testnet

Oracle configuration

The oracle uses randomness from the quicknet mainnet to provide randomness on Alephium.

How to access data

To consume randomness data, you’ll need to invoke the getLastRound method on the oracle contract. It will return the round ID of the latest update.

Using this round ID, you can call getRandomValue and will receive a return value of that randomness, the round ID and the BLS signature from the drand API.

Note that round IDs are used round-robin and will repeat after 1000 iterations.

Below is the DIARandomOracle contract implementation in :

Contract DIARandomOracle(
    mut admin: Address,
    mut lastRound: U256
) extends DIAOracleBase(admin) implements IDIARandomOracle {

    mapping[U256, DIARandomValue] randomValues

    event OracleUpdate(
        round: U256,
        randomness: ByteVec,
        signature: ByteVec
    )

    const MaxSlot = 1000

    enum ErrorCodes {
        InvalidRound = 1
        RoundKeyNotExist = 2
        RoundIsExpired = 3
    }

    pub fn getLastRound() -> U256 {
        return lastRound
    }

    pub fn getRandomValue(realRound: U256) -> DIARandomValue {
        let roundKey = realRound % MaxSlot
        assert!(randomValues.contains!(roundKey), ErrorCodes.RoundKeyNotExist)

        let randomValue = randomValues[roundKey]
        assert!(randomValue.round == realRound, ErrorCodes.RoundIsExpired)
        return randomValue
    }

    @using(preapprovedAssets = true, updateFields = true)
    pub fn setRandomValue(value: DIARandomValue) -> () {
        checkAdmin(callerAddress!())
        assert!(value.round > lastRound, ErrorCodes.InvalidRound)
 
        let roundKey = value.round % MaxSlot
        lastRound = value.round

        if (randomValues.contains!(roundKey)) {
            randomValues[roundKey] = value
        } else {
            randomValues.insert!(admin, roundKey, value)
        }

        emit OracleUpdate(value.round, value.randomness, value.signature)
    }
}

Support

You can learn more .

For developer assistance, connect with the DIA team directly on or .

Developers seeking other specialized, production-grade oracle with tailored data feeds and configurations can initiate the request by .

drand
Ralph
here
Discord
Telegram
contacting the DIA BD Team via Telegram
v1v4cBXP9L7M9ryZZCx7tuXuNb9pnDLGb3JJkPBpbR1Z
217k7FMPgahEQWCfSA1BN5TaxPsFovjPagpujkyxKDvS3