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
  • Overview
  • Setup
  • Usage
  • Example
Export as PDF
  1. How-to Guides
  2. Generate Randomness

WASM

Overview

The RandomOracle contract in ink! is designed to store random values for different rounds. Each round has an associated RandomData struct containing a randomness value, a signature, and the previous signature. The contract provides methods for setting random values and retrieving random values for a given round.

Setup

  1. Clone the repository:

git clone https://github.com/diadata-org/dia-wasm-oracle.git
cd dia-wasm-oracle/random-wasm-oracle
  1. Install required tools and dependencies:

cargo install --force --git https://github.com/paritytech/cargo-contract.git
rustup component add rust-src --toolchain nightly
rustup target add wasm32-unknown-unknown --toolchain nightly

Usage

  1. Build the contract:

cargo +nightly contract build
  1. Deploy contract using this UI

https://contracts-ui.substrate.io/

Example

To use the RandomOracle contract in your own project, follow these steps:

  1. In your own project, add the random-wasm-oracle as a dependency. Open your project's Cargo.toml and add the following:

[dependencies]
random-wasm-oracle = { path = "path/to/dia-wasm-oracle/random-wasm-oracle" }
  1. In your project's smart contract, import the necessary modules and types from the random-wasm-oracle crate:

use randomoracle::RandomOracleRef;
  1. In your contract's storage, add a RandomOracleRef field:

#[ink(storage)]
pub struct YourContract {
    // Your other fields...
    random_oracle: RandomOracleRef,
}
  1. In your contract's constructor, add a parameter for the RandomOracle contract's address and initialize the RandomOracleRef:

#[ink(constructor)]
pub fn new(random_oracle: AccountId) -> Self {
    Self {
        // Initialize your other fields...
        random_oracle: RandomOracleRef::from_account_id(random_oracle),
    }
}
  1. Implement methods to interact with the RandomOracle contract, e.g., getting random values for a specific round:

#[ink(message)]
pub fn get_random_value_for_round(&self, round: Vec<u8>) -> Vec<u8> {
    self.random_oracle.get_random_value_for_round(round)
}
  1. Build and deploy your contract, providing the RandomOracle contract's address https://shibuya.subscan.io/account/Y9YVxsyH8bza5zyK1AVW4iw1r7twVdoXMoDzWwdwraapvSM when instantiating your contract.

  2. Interact with your contract to call the methods that use the RandomOracle contract.

PreviousSolidityNextDemo Oracles

Last updated 2 months ago