Custom Blockchain Building on Substrate framework


The polkadot is very compatible with the multi-chain. Actually, we can’t have massively transactions around the world on one chain like the Bitcoin and Ethereum network. The polkadot depends on substrate which is opensource, module and framework to build the blockchain network. The substrate depends on the Rust programming language which is very fast and secured light. The both of substrate framework and Rust programming language are tool to incentive the polkadot blockchain ecosystem. In this article, I am going to describe how to build our own blockchain on substrate practically.

Proof of Existence Blockchain

In this article, we will build the proof of existence blockchain on the polkadot by the substrate framework,which means that we are going to run our own chain on the polkadot. For example ,imagine you are an author of some books ,then you need to proof you are actual author of the book. We will build such blockchain to implement this functionality. So you will put your name and the topic of book into the blockchain. So it should be immutable forever.I am not going to mention the blockchain use anymore here. Then let’s jump into main course.

  1. Pre-requirements

We have to use substrate framework to build our own blockchain as I mentioned above already. There are two things we have to do now .We will clone the substrate-node-template and substrate-ui-template from substrate github to be very fast on our development. Also we will build the runtime pallet about our own blockchain development in the pallet folder of the substrate-node-template project.

2. Auth-Pallet Building

The auth-pallet is the modular and the logic implementation how our blockchain works on our own chain.

#![cfg_attr(not(feature = "std"), no_std)]use frame_support::{decl_error, decl_event, decl_module, decl_storage, dispatch::DispatchResult, ensure,};use frame_system::ensure_signed;#[cfg(test)]use sp_std::vec::Vec<u8>;  // substrate pallet standard package mod tests;

we can create file inside auth-pallet folder of the pallets of substrate and copy and paste above code parts. Each pallet is the library of the runtime module to implement the state transaction function from one state to another one on chain.

decl_error: This allows the chain to be fired if the error causes while the runtime module is running.

decl_event: This allows the chain to be fired if the state change completes successfully.

decl_module: This allows external users to interact with the functionalities on the chain.

decl_storage: This allows user to save the data into the chain.

dispatch: This returns the result after the state change complete successfully on chain.

ensure: This is requirement to see the something is satisfied with some conditions. (It is similar to the require of solidity programming language).

Maybe ,you can feel boring now with these codes 🤓. So let’s jump more into next steps. Then you will become a good substrate developer.

Here are the macros which are described on substrate. important!!

decl_event!(pub enum Event<T>whereAccountId = <T as frame_system::Config>::AccountId,{
// This event emitted someone claim into chain

});decl_storage! {trait Store for Module<T: Config> as Proof {pub Proofs get(fn get_proof): map hasher(blake2_128_concat) T::AccountId => u8;}}decl_error! {pub enum Error for Module<T: Config> {/// Attempted to transfer than were available ErrorTransfer,}}decl_module! { pub struct Module<T:Config> for enum Call where origin: T::Origin{ // This will fire event in default

fn deposit_event() = default
// This function is external function to interact the users who wants to interact with our blockchain. The first parameter will be origin somehow and anytime and then add next params ...
fn claimInsert(origin,Vec<u8>)-> DispatchResult{
let sender = ensure_signed(origin)?; // OR

// store sender's data into chain
// emit event


After we code some logic inside the auth-pallet , we run cargo build command . Then It will happen to compile wasm file to upload on our chain.

Then we will run substrate-ui-template and connect the node which built on substrate to polkadot js in local environment . That’s all . You can see your chain on it now. That’s really awesome to run your own blockchain.




😀 Blockchain Specialist | Smart contract Developer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Kubernetes Deployment Dependencies

We are more than 75,000 people (stars 🌟) — awesome-go

GitHub repository avelino/awesome-go

SQL and RDBMS: The tech that stands the test of time.

Network+ Practice Labs: Configure IPv4 and IPv6 Addressing

Onwards to the next chapter!

Why Woodworking Will Make You a Better Coder

Alchera Face Authentication API beta is now available on RapidAPI!

Dev Academy’s Living Curriculum

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ding Tian

Ding Tian

😀 Blockchain Specialist | Smart contract Developer

More from Medium

Mint tokens on Solana using the Rust SDK

Building the staking smart contract with Solana blockchain

Tgrade Contracts Exposed

Sin7Y Tech Review (18): Zero-Knowledge Proof Algorithm: ZK-Stark — FRI Protocol