Prerequisites

If you do not have substrate installed on your machine, run:

curl https://getsubstrate.io -sSf | bash

Substrate Templates

Substrate package contains the UI, module, and runtime templates for building with Substrate. The substrate-module-template is the simplest path to experimenting with Substrate. Modules are modular pieces of code that can be composed within a single runtime.

Likewise, the substrate-node-template provides all necessary scaffolding for running a functional Substrate node. Each Substrate runtime contains multiple modules that comprise the logic of the defined Substrate blockchain.

The substrate-ui provides a template for building a compatible UI that works with the node template.

Runtime Module

Clone the substrate-module-template

$ git clone https://github.com/shawntabrizi/substrate-module-template

build with

$ cargo build

test with

$ cargo test

Runtime Node

Clone the substrate-node-template and add module logic to runtime/src/template.rs.

Update the runtime root lib.rs file to include the new Event<T> type under the module's Trait implementation


# #![allow(unused_variables)]
#fn main() {
/// in root `lib.rs`
mod mymodule;

impl mymodule::Trait for Runtime {
    type Event = Event<T>;
}
#}

Include the Event<T> type in the module's definition in the construct_runtime macro block.


# #![allow(unused_variables)]
#fn main() {
/// in root `lib.rs`
construct_runtime!(
    pub enum Runtime for Log(InteralLog: DigestItem<Hash, Ed25519AuthorityId) where
        Block = Block,
        NodeBlock = opaque::Block,
        InherentData = BasicInherentData
    {
        ...
        MyModule: mymodule::{Module, Call, Storage, Event<T>},
    }
);
#}

Updating the Runtime

Compile runtime binaries

cd runtime
cargo build --release

Delete the old chain before you start the new one (this is a very useful command sequence when building and testing runtimes!)

./target/release/substrate-example purge-chain --dev
./target/release/substrate-example --dev