Coder Social home page Coder Social logo

sbnair / substrate-runtime-contract-sample Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gautamdhameja/substrate-runtime-contract-sample

0.0 1.0 0.0 276 KB

A sample Substrate runtime showing interaction between runtime modules (pallets) and smart contracts (ink!).

License: The Unlicense

Rust 97.85% Shell 0.79% Nix 1.37%

substrate-runtime-contract-sample's Introduction

Substrate Runtime-Contract Sample

A sample Substrate runtime showing interaction between runtime modules (pallets) and smart contracts (ink!).

Runtime to Contract Interaction

In the template module (pallet) in the runtime, following funtions are used for contract interaction:

  • call_contract
  • get_contract_storage

Contract to Runtime Interaction

In the custom_type contract, the read_custom_runtime funtion is used to query the runtime storage for a custom struct.

Custom types for Polkadot JS

{
  "Foo": {
    "id": "u32",
    "data": "Vec<u8>"
  }
}

Generating Storage Keys

Keys to storage items in substrate runtime are constructed by hashing the raw key.

Refer to the substrate documentation about storage types and key construction.

Build Node and Runtime

Install Rust:

curl https://sh.rustup.rs -sSf | sh

Initialize your Wasm Build environment:

./scripts/init.sh

Build Wasm and native code:

cargo build --release

Build Contract

Install Cargo Contract:

cargo install --force --git https://github.com/paritytech/cargo-contract

Inside the contracts/custom_type sub-directory, run the following commands to build the contract and generate its metadata:

cargo +nightly contract build
cargo +nightly contract generate-metadata

Run

Start a development chain with:

./target/release/substrate-runtime-contract-sample --dev

Detailed logs may be shown by running the node with the following environment variables set: RUST_LOG=debug RUST_BACKTRACE=1 cargo run -- --dev.

Additional CLI usage options are available and may be shown by running cargo run -- --help.

Deploy the contract

Once the Substrate node is running, deploy and instantiate the contract using the Polkadot JS portal.

substrate-runtime-contract-sample's People

Contributors

ascjones avatar gautamdhameja avatar riusricardo avatar satyamakgec avatar

Watchers

James Cloos avatar

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.