Cosmos was one of the first to step into bringing the “Internet of Blockchains” to life. Cosmos consists of multiple independent blockchains running in parallel, backed up by the Proof-of-Stake Byzantine Fault Tolerant Algorithm, such as Tendermint consensus. Cosmos SDK makes use of Tendermint, which keeps check that the system reaches consensus even if a node in the system fails or behaves maliciously. Cosmos SDK aims to provide an open-source framework for developers to create interoperable customized blockchains. Cosmos SDK is powerful enough to tackle scalability, usability, governance, and security related issues. Cosmos has made it so much easier to build on top of the Cosmos network. Moving ahead, let’s have a brief view at some Cosmos tools meant for developer’s ease.
Cosmos SDK Modules: While most of the logic is defined by modules; they are also seen as the building blocks to construct the entire decentralized application. The module consists of the core which provides basic functionalities, the boilerplate implementation is communicated with the underlying consensus engine. Working in modules makes it easier to build complex blockchain applications.
Tendermint: Tendermint, facilitating creation of Proof-of-Stake systems is also known as gold consensus engine. It is the most popular, mainly because of the high security it provides to the developers.
Inter-Blockchain Communication (IBC): This tool lets the distributed ledgers spread across the network communicate with each other for exchange of data and value. IBC defines a set of standards to transmit data and allows compatible supported ledgers to be interconnected without any restrictions.
Let’s learn how to get started with Cosmos.
We’ll run through the initial steps for creating your own blockchain application on top of Cosmos SDK Network.
-Golang > 1.15 installed
-GitHub account and GitHub CLI/GitHub Desktop
For this setup we will be using Starport version 0.13.1, an easy tool to use for building blockchains.
To install starport into /usr/local/bin, run the following command:
These are the files that you must create in your system which make up the application.
│ ├── nameservicecli
│ │ └── main.go
│ └── nameserviced
│ └── main.go
│ ├── cli
│ │ ├── query.go
│ │ └── tx.go
│ └── rest
│ ├── query.go
│ ├── rest.go
│ └── tx.go
│ ├── keeper.go
│ └── querier.go
│ ├── codec.go
│ ├── errors.go
│ ├── expected_keepers.go
│ ├── key.go
│ ├── msgs.go
│ ├── querier.go
│ └── types.go
A blockchain application is just a replicated deterministic state machine which consists of two main parts: state and messages. As a developer you are required to define state machine. Cosmos SDK is a modular framework. Each module contains its own messages. Before we have a close look at what state and messages are. Let’s view the modules which help create the state machine and will be needed for nameservice application.
auth: This module describes accounts and fees, gives access to these functionalities to the rest of your application.
bank: This module allows the application to create and manage tokens and its balances.
staking: This module enables the application to have validators that people can delegate to.
distribution: This module will help to distribute between validators and delegators effectively.
slashing: This module disincentivizes people such as validators with value staked in the network.
supply: This module will contain the total supply of the chain.
nameservice: This will be created at the end and does not exist yet. It holds and manages the core logic for nameservice application you are building. Our application will mainly be built on this specific piece.
It is to be pointed here that why nameservice contains so much importance. Not to forget, the main application goal here is that users will be able to buy unused names, or even sell or trade names. Coming back to two integral parts of the application, state, and messages:
The state represents current position of your application. The state will indicate how much token balance is in each account, what are the owners, and price of each name, and to what value each name resolves to. For now, you don’t need to be concerned about what auth and bank will contain. The part you need to be concerned is of how to relate state specifically to your nameservice module. For containing data, you will be using multistore to store all key/value pairs such as mentioned earlier, name’s value, owner, and price.
Messages are internal part of transactions. Hence, they trigger state transition. Each module defines a list of messages and how to handle them. Here are two types of messages you need to implement the required functionality for your nameservice application:
MsgSetName: This message allows to locate name for name owners
MsgBuyName: This message allows accounts to buy a name and become its owner.
When someone buys a name and replaces the ownership, he is supposed to pay higher price for it than its previous owner did, close to what happens in property ownership or for real world entities. If the name does not have a previous owner yet, they must burn a MinPrice amount. Now, since you understand the foundation and layering of how the ground is set up for implementation. Its time that you get started with your own implementation as the framework is ready to receive commands from you to create your first ever application!
So far, Cosmos Ecosystem has surfaced and emerged as what it claimed to be. Cosmos claimed not only to let individual blockchains communicate with each other in a decentralized way but also among their prime agendas, it prominently stood to make transactions quicker and create blockchains that can maintain sovereignty. Yet, it is proving by how quickly it is expanding with its projects. There are 260+ diverse applications and services built on Cosmos. From numerous examples some include such as Terra (LUNA), Thor Chain, Secret Network, Compound Gateway, Osmosis, Kava, Akash and of course, the Cosmos Hub.
Next up, we’ll walk into a sub-system of Cosmos, Osmosis.zone, the future Aave of Cosmos Ecosystem.