Getting Started

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!

Requirements

Tutorial

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

Start by creating a new git repository:

mkdir -p $GOPATH/src/github.com/{ .Username }/nameservice
cd $GOPATH/src/github.com/{ .Username }/nameservice
git init
1
2
3

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

Tutorial parts

  1. Design the application.
  2. Begin the implementation of your application in ./app.go.
  3. Start building your module by defining some basic Types.
  4. Define the keys needed for your module key
  5. Create the main core of the module using the Keeper.
  6. Define state transitions through Msgs and Handlers.
  7. Make views on your state machine with Queriers.
  8. Create the alias file
  9. Register your types in the encoding format using sdk.Codec.
  10. Create CLI interactions for your module.
  11. Create HTTP routes for clients to access your nameservice.
  12. Implement the AppModule interface
  13. Configure your Genesis state.
  14. Import your module and finish building your application!
  15. Create the nsd and nscli entry points to your application.
  16. Setup dependency management using go.mod.
  17. Build and run the example.
  18. Run REST routes.

Click here to get started with the tutorial!