Skip to content

A smart contract toolkit for using verifiable randomness in ink! smart contracts

License

Notifications You must be signed in to change notification settings

ideal-lab5/contracts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ideal Labs Contracts Toolkit

Built with ink!

Tools and examples for building ink! smart contracts that use publicly verifiable on-chain randomness.

Usage

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.

Configuration

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;
    ...
}

Chain Extension

self.env()
    .extension()
    .random();

Build

cargo +nightly contract build

Testing

Unit Tests

Unit tests can be run with

cargo +nightly test

E2E tests

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

Note on Binaryen/wasm-opt

If your package manager doesn't have binaryen versions >= 99, then:

# 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.