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.
All contracts under the examples folder are outdated and 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 test
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-tests
If 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-opt
Verify the installation by running wasm-opt --version
. If the command executes and the printed version matches the downloaded version, then the installation is complete.