Oracle details

ChainAddress
Alephium Mainnetv1v4cBXP9L7M9ryZZCx7tuXuNb9pnDLGb3JJkPBpbR1Z
Alephium Testnet217k7FMPgahEQWCfSA1BN5TaxPsFovjPagpujkyxKDvS3

Oracle configuration

The oracle uses drand 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 Ralph:

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)
    }
}

You can learn more here.

Support

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

Developers seeking other specialized, production-grade oracle with tailored data feeds and configurations can initiate the request by contacting the DIA BD Team via Telegram.