Tools and examples for building ink! smart contracts that use publicly verifiable on-chain randomness.
Follow the ink! documentation for a complete guide on getting started.
To use this library, you must be running a node that supports:
- arkworks host functions
- the drand bridge pallet
- ink! smart contracts
You can find an example node here.
cargo contract instantiate myContract.contract --constructor new \
--args some args here \
--suri //Alice --url ws://127.0.0.1:9944 -xexamples are under construction
To use in a smart contract, at idl-contract-extension to the cargo.toml
[dependencies]
idl-contract-extension = { git = "https://github.com/ideal-lab5/contracts.git", default-features = false, features = ["ink-as-dependency"] }
[features]
std = [
...
"idl-contract-extension/std",
]and configure the contract environment to use the DrandEnvironment
use idl_contract_extension::ext::DrandEnvironment;
#[ink::contract(env = DrandEnvironment)]
mod your_smart_contract {
use crate::DrandEnvironment;
...
}self.env()
.extension()
.random();cargo +nightly contract build
Unit tests can be run with
cargo +nightly testTo test functions that call the chain extension, it can be mocked like:
struct MockDrandExtension;
impl ink_env::test::ChainExtension for MockDrandExtension {
fn func_id(&self) -> u32 {
1101
}
fn call(&mut self, _input: &[u8], output: &mut Vec<u8>) -> u32 {
let mut ret = [1;32];
ret[0] = 0;
scale::Encode::encode_to(&ret, output);
0
}
}
ink_env::test::register_chain_extension(MockETFExtension);End-to-end tests reequires that you run a node locally and provide it's absolute path (e.g. /home/.../substrate/target/release/node-template).
export CONTRACTS_NODE="YOUR_CONTRACTS_NODE_PATH"
cargo +nightly test --features e2e-testsIf your package manager doesn't have binaryen versions >= 99, then:
-
Download the latest version here: https://github.com/WebAssembly/binaryen/releases
-
follow these instrutions to install:
# unzip the tarball
sudo tar xzvf binaryezn-version_100-x86_64-linux.tar.gz
# update permissions
chmod +x binaryen-version_100
# move to /opt
sudo mv binaryen-version_100 /opt/
# navigate to /opt
cd /opt
# make it executable
chmod +x binaryen-version_100
# add symbolic link to /usr/bin
sudo ln -s /opt/binaryen-version_100/bin/wasm-opt /usr/bin/wasm-optVerify the installation by running wasm-opt --version. If the command executes and the printed version matches the downloaded version, then the installation is complete.