Comment on page

Access WASM random oracle

This page contains information about a RandomOracle smart contract designed for the Substrate ecosystem.


The RandomOracle contract 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.


  1. 1.
    Clone the repository:
git clone
cd dia-wasm-oracle/random-wasm-oracle
  1. 2.
    Install required tools and dependencies:
cargo install --force --git
rustup component add rust-src --toolchain nightly
rustup target add wasm32-unknown-unknown --toolchain nightly


  1. 3.
    Build the contract:
cargo +nightly contract build
  1. 4.
    Deploy contract using this UI


To use the RandomOracle contract in your own project, follow these steps:
  1. 1.
    In your own project, add the random-wasm-oracle as a dependency. Open your project's Cargo.toml and add the following:
random-wasm-oracle = { path = "path/to/dia-wasm-oracle/random-wasm-oracle" }
  1. 2.
    In your project's smart contract, import the necessary modules and types from the random-wasm-oracle crate:
use randomoracle::RandomOracleRef;
  1. 3.
    In your contract's storage, add a RandomOracleRef field:
pub struct YourContract {
// Your other fields...
random_oracle: RandomOracleRef,
  1. 4.
    In your contract's constructor, add a parameter for the RandomOracle contract's address and initialize the RandomOracleRef:
pub fn new(random_oracle: AccountId) -> Self {
Self {
// Initialize your other fields...
random_oracle: RandomOracleRef::from_account_id(random_oracle),
  1. 5.
    Implement methods to interact with the RandomOracle contract, e.g., getting random values for a specific round:
pub fn get_random_value_for_round(&self, round: Vec<u8>) -> Vec<u8> {
  1. 6.
    Build and deploy your contract, providing the RandomOracle contract's address when instantiating your contract.
  2. 7.
    Interact with your contract to call the methods that use the RandomOracle contract.