DEV Community

Cover image for Creating Your First Substrate Chain
@codingsh
@codingsh

Posted on

Creating Your First Substrate Chain

Introduction

In this tutorial, you will learn to create a custom "Proof Of Existence" blockchain using the Substrate blockchain development framework.

This tutorial is aimed at someone who has never touched Substrate before, and wants to get a basic and quick understanding of what Substrate is all about. We will not be going into depth about the intricacies of developing on Substrate, but will hopefully satisfy your curiosity so that you will continue this journey.

This tutorial should take you about 1 hour to complete. We will be using the Rust programming language and ReactJS, but you do not need to know these to be able to complete this guide. We will provide you with working code snippets and explain what all the code does at a high level.

We only expect that:

  • You are generally familiar with software development and using the terminal.
  • You are generally familiar with blockchains and smart contract platforms.
  • You are open to learning about the bleeding edge of blockchain development. It is important to emphasize again that Substrate is truly a bleeding edge framework. It is moving fast, and as a result, may sometimes break or cause issues. If you run into an issue on this tutorial, we are here to help!

You can create a new issue or contact us directly on Riot.

What you will be doing

Before we even get started, let's layout what we are going to do over the course of this tutorial. We will:

  • Set up your computer to be able to develop on Substrate.
  • Use a template project to start running Substrate right away.
  • Modify this template project to add our own custom logic.
  • Modify a front-end template to interact with your brand new blockchain.

Set Up Your Computer

Normally we would teach you more about the Substrate blockchain development framework and the Proof of Existence blockchain you will be building. However, setting up your computer for Substrate development can take a while.

To optimize your time, we will have you start the setup process. In the next section, while things are compiling, you will learn more about Substrate and what we are building.

Prerequisites

To develop on Substrate, your computer needs some prerequisites to establish a working development environment.

Note: Setting up your computer is probably the hardest part of this tutorial, so don't let this discourage you.

Substrate Development

If you are using a Unix based machine (Linux, MacOS), we have created a simple one-liner to get all of those prerequisites installed for you:

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

Learn what this script does.
If you are using Windows and do not have the Windows Subsystem for Linux, the process is a bit harder, but well documented here.

Front-End Development

This tutorial also uses a custom ReactJS front-end which we will modify for interacting with our custom Substrate blockchain.

To use the front-end project, you need to install Yarn, which may also require you separately install Node.js. You can do that while the getsubstrate-script is still running.

Compiling Substrate

Once everything is installed, you need to set up the skeleton for our project. Fortunately, there is a simple template project to help you get started building on Substrate.

1 - Clone the Substrate Node Template and Substrate Front-End Template

git clone https://github.com/substrate-developer-hub/substrate-node-template
git clone https://github.com/substrate-developer-hub/substrate-front-end-template

2 - Initialize your WebAssembly build environment

# Update Rust
rustup update nightly
rustup update stable

# Add Wasm target
rustup target add wasm32-unknown-unknown --toolchain nightly

# Install `wasm-gc` to slim Wasm binaries
cargo +nightly install --git https://github.com/alexcrichton/wasm-gc --force

3- Compile your Substrate node

cd substrate-node-template/
cargo build --release

This final compilation can take up to 15 minutes depending on your computer hardware.

Top comments (0)