Create your blockchain using Cosmos SDK | Ignite | Tendermint.

Pankaj Singh Rathore
7 min readDec 10, 2022

As we all know, to build blockchain we need lots of expertise in core concepts of computers and relevant programming knowledge for writing entire blockchain logic per different use cases. To minimize these efforts here we will use cosmos SDK for building the simple blockchain.

What is Cosmos?

Cosmos is a blockchain ecosystem, which provides the functionality to develop the entire blockchain and blockchain-based apps in a short time without putting effort into the core because the cosmos will provide the entire skeleton of the blockchain for developers to develop things.

Let’s start baking our own blockchain.

Step 1:- Installing prerequisites.

  • Install Docker Engine.
  • Install Go.
  • Install Node JS.
  • Install Rust.

Step 2:- Need to install cosmos-based tools.

Type directly in the terminal

If you find any error just install using sudo in front of the command.

Step 3:- let's Build the blockchain.

  • Now we will create our blockchain,
  • I have created a directory for storing my blockchain files, so you can also create them according to your needs.
  • Use the command in a folder to create a blockchain.
  • My chain name is “Sample_Chain”.
pankajrathore@Pankajs-MacBook-Pro Cosmos % ignite scaffold chain Sample_Chain
  • After successful completion, the success message looks like the below.
  • Once you see the success message just go into your chain folder to start your chain and for testing on the network.
  • Change your directory to your chain.
  • Now use the command to start your chain.
pankajrathore@Pankajs-MacBook-Pro Sample_Chain % ignite chain serve 

once you type this command the required packages & dependencies were going to install and take some time according to your CPU spec.

  • The success message looks like below.

Step 4:- Let's Explore our newly created blockchain.

Just explore the shown URL in the browser from your terminal for exploring the blockchain and faucet.

There are several functionalities to explore, just follow me step by step.

Note:- The for enabling all the defi functionality in our chain we will use the pre-built Cosmos Modules here for adding Dex, Pools, Govern etc.

Enable Dex Functionality

  • Here we have to enable dex functionality in our blockchain so we will able to create pools and enable users to stake some amount on our chain. use the command below to scaffold the dex.
pankajrathore@Pankajs-MacBook-Pro Sample_Chain % ignite s module dex --ibc

a success message is like below.

Now we have to add a pool message or functionality after creating dex.

  • we have to create a pool functionality for make enable staking tokens on our chain. use the below command for creating the pool.
pankajrathore@Pankajs-MacBook-Pro Sample_Chain % ignite s list pool amount:coin height:int --module dex
  • we have to create the pool under the dex module for scaffold with our dex.

a success message is like below.

after creating the pool we have to provide some liquidity to start things on your chain.

We have to add liquidity now.

  • For enabling staking we have to provide liquidity to our pool but before that, we have to add the functionality of adding liquidity in our newly created pool. Use below command
pankajrathore@Pankajs-MacBook-Pro Sample_Chain % ignite s message add-liquidity amount:coin denom --module dex

a success message is like below.

Let’s add my own account to a chain

  • and open your chain folder in any code editor like vs code, atom, etc. For making changes in the config.yml file.
  • Now let’s add our new account in the account section of the config file.
  • You can also add more validators and faucets as per your need.
  • once add the new account save the file and start the chain for seeing the new account on the chain.

The next step is tricky but simple. please follow all the steps with focus and in sequential order.

Let's Check our single binary file and commands.

  • After compiling the entire chain our code is converted into a single binary file by GO and the names look like this, my chain name is Sample_Chain and the Binary file is created with the name Sample_Chaind. just add ‘d’ behind your chain name for accessing binary and for using or executing a command from your binary file within the blockchain folder.
  • use the command to check all your blockchain functionality.
pankajrathore@Pankajs-MacBook-Pro Sample_Chain % Sample_Chaind tx

like I would like to check some messages in my dex so I will go through like this.

pankajrathore@Pankajs-MacBook-Pro Sample_Chain % Sample_Chaind tx dex

Let’s create a pool.

  • Before creating a pool start your chain in the terminal and parallel open the new terminal for executing the commands for creating the pool on the chain. use the below command for creating the pool using a binary chain file.
pankajrathore@Pankajs-MacBook-Pro Sample_Chain % Sample_Chaind tx dex create-pool 100stake 5 --from pankaj

success transaction message is like.

auth_info:
fee:
amount: []
gas_limit: "200000"
granter: ""
payer: ""
signer_infos: []
tip: null
body:
extension_options: []
memo: ""
messages:
- '@type': /sample_chain.dex.MsgCreatePool
amount:
amount: "100"
denom: stake
creator: cosmos1pt9htcnq9wk2llkt3ae5ec5ty65s5f3ta4w0ym
height: 5
non_critical_extension_options: []
timeout_height: "0"
signatures: []
confirm transaction before signing and broadcasting [y/N]: y
code: 0
codespace: ""
data: 12290A272F73616D706C655F636861696E2E6465782E4D7367437265617465506F6F6C526573706F6E7365
events:
- attributes:
- index: true
key: ZmVl
value: ""
- index: true
key: ZmVlX3BheWVy
value: Y29zbW9zMXB0OWh0Y25xOXdrMmxsa3QzYWU1ZWM1dHk2NXM1ZjN0YTR3MHlt
type: tx
- attributes:
- index: true
key: YWNjX3NlcQ==
value: Y29zbW9zMXB0OWh0Y25xOXdrMmxsa3QzYWU1ZWM1dHk2NXM1ZjN0YTR3MHltLzA=
type: tx
- attributes:
- index: true
key: c2lnbmF0dXJl
value: MUZVZXdaVy9WdHZLSnZEMWszRkg5dTNtT3NjRlhzR2pXZFY1ZUlZMXNjVUM1aGRid1hoMFFodFZndC83bFZ4dEt6bDFlL09lZGthbG0xd1lWMW9tSmc9PQ==
type: tx
- attributes:
- index: true
key: YWN0aW9u
value: L3NhbXBsZV9jaGFpbi5kZXguTXNnQ3JlYXRlUG9vbA==
type: message
gas_used: "61693"
gas_wanted: "200000"
height: "73"
info: ""
logs:
- events:
- attributes:
- key: action
value: /sample_chain.dex.MsgCreatePool
type: message
log: ""
msg_index: 0
raw_log: '[{"msg_index":0,"events":[{"type":"message","attributes":[{"key":"action","value":"/sample_chain.dex.MsgCreatePool"}]}]}]'
timestamp: ""
tx: null
txhash: B30D3E417DC1F33D3EC664ABC2B068D927BCA0CF67AF8FC48D3F1C6E367E9A7F

Congrats, you have created a pool on your chain.

Let’s check out the created pool, use the command below.

pankajrathore@Pankajs-MacBook-Pro Sample_Chain % Sample_Chaind q dex list-pool

Let’s add more liquidity to our pool in the same way. use the command below.

pankajrathore@Pankajs-MacBook-Pro Sample_Chain % Sample_Chaind tx dex add-liquidity 100stake 5 --from pankaj

success transaction

pankajrathore@Pankajs-MacBook-Pro Sample_Chain % Sample_Chaind tx dex add-liquidity 100stake 5 --from pankaj
auth_info:
fee:
amount: []
gas_limit: "200000"
granter: ""
payer: ""
signer_infos: []
tip: null
body:
extension_options: []
memo: ""
messages:
- '@type': /sample_chain.dex.MsgAddLiquidity
amount:
amount: "100"
denom: stake
creator: cosmos1pt9htcnq9wk2llkt3ae5ec5ty65s5f3ta4w0ym
denom: "5"
non_critical_extension_options: []
timeout_height: "0"
signatures: []
confirm transaction before signing and broadcasting [y/N]: y
code: 0
codespace: ""
data: 122B0A292F73616D706C655F636861696E2E6465782E4D73674164644C6971756964697479526573706F6E7365
events:
- attributes:
- index: true
key: ZmVl
value: ""
- index: true
key: ZmVlX3BheWVy
value: Y29zbW9zMXB0OWh0Y25xOXdrMmxsa3QzYWU1ZWM1dHk2NXM1ZjN0YTR3MHlt
type: tx
- attributes:
- index: true
key: YWNjX3NlcQ==
value: Y29zbW9zMXB0OWh0Y25xOXdrMmxsa3QzYWU1ZWM1dHk2NXM1ZjN0YTR3MHltLzE=
type: tx
- attributes:
- index: true
key: c2lnbmF0dXJl
value: VVBKVUxiMjdJeGJweXRTVXdRUU1IQktoUERJODNiZWlBSHdnZjB1S2t0NXkyK3h0aHJlOEI0NDNLcldxQnZBOS9WMjNsVVN3MSswVjd4d3l2bDlYalE9PQ==
type: tx
- attributes:
- index: true
key: YWN0aW9u
value: L3NhbXBsZV9jaGFpbi5kZXguTXNnQWRkTGlxdWlkaXR5
type: message
gas_used: "43548"
gas_wanted: "200000"
height: "1889"
info: ""
logs:
- events:
- attributes:
- key: action
value: /sample_chain.dex.MsgAddLiquidity
type: message
log: ""
msg_index: 0
raw_log: '[{"msg_index":0,"events":[{"type":"message","attributes":[{"key":"action","value":"/sample_chain.dex.MsgAddLiquidity"}]}]}]'
timestamp: ""
tx: null
txhash: 1CCE16A9CBDA692AB0DF121861A117356F23DDC60402C13ACFB4623DD073022D

After completing all the things you need to build the frontend app you can see the vue folder in your chain folder just install packages through npm and start to build the frontend. here we successfully created our own blockchain based on cosmos SDK.

Watched My Youtube Video.

--

--

Pankaj Singh Rathore

Blockchain Developer {Solidity, Rust, ZKP } | Entrepreneur | Explorer|. Connect with me — https://linktr.ee/pankajsinghrathore