Giter Site home page Giter Site logo

ideal-lab5 / contracts Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 3.0 178.88 MB

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

Home Page: https://docs.idealabs.network

License: Apache License 2.0

Rust 96.40% Shell 3.60%
ink-smart-contract randomness-beacon rust smart-contracts substrate timelock-encryption web3

contracts's Introduction

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.