Rise In Logo



Polkadot Fundamentals and Substrate Development

Building A blockchain

Since we have Rust installed, it is now time to build our own blockchain using Substrate and experiencing the powerful features it brings.

Compile and Starting a Substrate Node

The template for a substrate node is present on github and this is the one we need to clone to be able to start a substrate node on our system.

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

Let’s change our directory and go inside the project that we’ve just cloned - 

  • cd substrate-node-template

It’s a good idea to always create a new branch, so that you can compare with the original project in case something goes wrong or you make some wrong changes to the project by mistake. So, let’s create a new branch -

git switch -c my-new-branch

To start the node, we first need to build and compile this project and then we will get the compiled file that we can run. We will use the “--release” flag to build optimized artifacts.

cargo build --release

Now we will start the node with the following command - 

./target/release/node-template --dev

The –dev flag indicates that we want the node to run in development mode. This option is great during development because it deletes all active data such as keys, blockchain database and networking information when you stop the node.

After this you should see the node running in your terminal

Install and Starting Front-End Template

Substrate also has a front end template for the dashboard so you can interact with the node through a UI and not just through the terminal.

For the front end, yarn and nodeJS are both required.

So first, check your nodejs and yarn versions - 

node --version
yarn --version

If you don’t have these, feel free to install before proceeding.

Just like we cloned the template for the node, we need to clone the project that has the code for the front-end template -

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

We now need to change our directory to the project we just cloned - 

cd substrate-front-end-template

Now we will install the project using yarn - 

yarn install

And now we just have to start the front end with the following command - 

yarn start

http://localhost:8000/ will automatically be opened in your default browser once the front end starts, but you can also open it manually. Now from the dashboard, you will be able to interact with the node.

Transfer Funds

On the dashboard, you will notice the “balances” section, look at the balances of various users such as Dave, who have zero balance.

Now we will try and transfer some money to Dave.

Select dave from the list and transfer at least 1000000000000 to dave.

All we need to do is first check the balances table and see if the value was transferred to Dave and also need to check the events table for the transfer event.

Stop Node

After a successful transfer, you can continue to explore the front-end template components or stop the local Substrate node to erase any state changes you have made. Because you specified the --dev option when you started the node, stopping the local node stops the blockchain and purges all persistent block data so that you can start with a clean state next time you start the node.

To stop the local Substrate node:

  • Return to the terminal shell where the node output is displayed.
  • Press Control-c to terminate the running process.
  • Verify your terminal returns to the terminal prompt in the substrate-node-template directory.

Project

Comments

You need to enroll in the course to be able to comment!

Stay in the know

Never miss updates on new programs and opportunities.

Rise In Logo

Rise together in web3!