In this tutorial, you will build a functional Cosmos SDK application and, in the process, learn the basic concepts and structures of the SDK. The example will showcase how quickly and easily you can build your own blockchain from scratch on top of the Cosmos SDK.
By the end of this tutorial you will have a functional nameservice
application, a mapping of strings to other strings (map[string]string
). This is similar to Namecoin, ENS, or Handshake, which all model the traditional DNS systems (map[domain]zonefile
). Users will be able to buy unused names, or sell/trade their name.
All of the final source code for this tutorial project is in this directory (and compiles). However, it is best to follow along manually and try building the project yourself!
golang
>1.12.1 installed- A working
$GOPATH
- Desire to create your own blockchain!
Through the course of this tutorial you will create the following files that make up your application:
./nameservice
├── Gopkg.toml
├── Makefile
├── app.go
├── cmd
│ ├── nscli
│ │ └── main.go
│ └── nsd
│ └── main.go
└── x
└── nameservice
├── client
│ ├── cli
│ │ ├── query.go
│ │ └── tx.go
│ └── rest
│ └── rest.go
├── types
├── key.go
├── msgs.go
├── querier.go
└── types.go
├── alias.go
├── codec.go
├── handler.go
├── keeper.go
├── querier.go
├── module.go
└── geneis.go
Start by creating a new git repository:
mkdir -p $GOPATH/src/github.com/{ .Username }/nameservice
cd $GOPATH/src/github.com/{ .Username }/nameservice
git init
Then, just follow along! The first step describes the design of your application. If you want to jump directly to the coding section, you can start with the second step
- Design the application.
- Begin the implementation of your application in
./app.go
. - Start building your module by defining some basic
Types
. - Define the keys needed for your module
key
- Create the main core of the module using the
Keeper
. - Define state transitions through
Msgs
andHandlers
. - Make views on your state machine with
Queriers
. - Create the
alias file
- Register your types in the encoding format using
sdk.Codec
. - Create CLI interactions for your module.
- Create HTTP routes for clients to access your nameservice.
- Implement the AppModule interface
- Configure your Genesis state.
- Import your module and finish building your application!
- Create the
nsd
andnscli
entry points to your application. - Setup dependency management using
go.mod
. - Build and run the example.
- Run REST routes.