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.Clone the repository:
git clone https://github.com/diadata-org/dia-wasm-oracle.git
cd dia-wasm-oracle/random-wasm-oracle
- 2.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
- 3.Build the contract:
cargo +nightly contract build
- 4.Deploy contract using this UI
https://contracts-ui.substrate.io/
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" }
- 2.In your project's smart contract, import the necessary modules and types from the
random-wasm-oracle
crate:
use randomoracle::RandomOracleRef;
- 3.In your contract's storage, add a RandomOracleRef field:
#[ink(storage)]
pub struct YourContract {
// Your other fields...
random_oracle: RandomOracleRef,
}
- 4.In your contract's constructor, add a parameter for the
RandomOracle
contract's address and initialize theRandomOracleRef
:
#[ink(constructor)]
pub fn new(random_oracle: AccountId) -> Self {
Self {
// Initialize your other fields...
random_oracle: RandomOracleRef::from_account_id(random_oracle),
}
}
- 5.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)
}
- 6.Build and deploy your contract, providing the
RandomOracle
contract's addresshttps://shibuya.subscan.io/account/Y9YVxsyH8bza5zyK1AVW4iw1r7twVdoXMoDzWwdwraapvSM
when instantiating your contract. - 7.Interact with your contract to call the methods that use the
RandomOracle
contract.
Last modified 5mo ago