Git Product home page Git Product logo

contract-demo's Introduction

Intro

This repo is a simple Substrate style wasm smart contract for a secret registry.

Install Node.js

please reference to Node.js Website

  • We recommend you to install yarn as an alternative to npm . Simple run npm install --global yarn

  • The repo is tested with nodejs version 14.6.0 , to check on your nodejs version node -v , to switch version of node, I recommend using n by TJ.

Setup the Substrate smart contract development environment

A good general guide to setup the environment for Substrate environment can be founded here.

  1. Install Rust for help: refer to Rust Website

    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
    source $HOME/.cargo/env

    Check your installed version

    rustc --version
    cargo --version

    This guides is tested with rustc 1.50.0 (cb75ad5db 2021-02-10) and cargo 1.50.0 (f04e7fab7 2021-02-04)

  2. Install Binaryen. You can simply install with Homebrew on macOS

    brew install binaryen

    To install Homebrew use

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  3. Install cargo-contract

    cargo install --force cargo-contract
  4. Grab a local Substrate blockchain node with pallet-contract included. There are many options: jupiter is the one we choose. Alternatively, you can get canvas by Parity. Rust is known for compiling slowly. It took me an hour to compile jupiter.

    • To use jupiter, follow this guide.

    • To use canvas, follow this guide.

    • Lastly, fire up the local blockchain

      path-to-jupiter-repo/target/release/jupiter-prep --dev
      # OR with Canvas
      canvas --dev --tmp
      

      You can visit https://ipfs.io/ipns/dotapps.io and choose to connect to ws://127.0.0.1:9944 to have a visual portal to interact with the blockchain.

My Environment

Codes are tested with the following environment:

binaryen: version 101
cargo: cargo 1.55.0 (32da73ab1 2021-08-23)
cargo-contract: cargo-contract 0.10.0
node: v14.16.0
rust: rustc 1.51.0 (2fd73fabe 2021-03-23)

canvas: canvas 0.1.0-25fd60f-x86_64-linux-gnu
OS Version: macOS Big Sur 11.0.1

ts-node: v10.0.0
mocha: 8.4.0

Node Packages Please refer to the package.json

Run Test

  1. Clone this repo to your local environment & install dependencies
git clone [email protected]:skyekiwi/contract-demo.git
yarn
  1. (Optional) Create .env files at the project home directory and write your seed phrase to it. Inject a seed phrase only if you want to deploy the contract.
SEED_PHRASE = 'xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx'
  1. Run Tests. The process can take somewhere between 3minutes to 10 minutes, depends on network connection.
yarn test
  1. Relax. The test should be able to finish within 10 minutes.

LICENSE

Apache 2.0. See the LICNESE File.

Contact

Email: [email protected]
Telegram: @songzhou26

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.