Follow our simple nameservice application tutorial to build your own decentralized application running on its own blockchain with the Cosmos SDK.
Download the tutorial: github.com/cosmos/sdk-application-tutorial
2. Before we begin...
Talkshop: Talk + Workshop
(Interactive presentation)
Download the tutorial
github.com/cosmos/sdk-application-tutorial
goes in $GO_PATH/src/github.com/cosmos/
make get_tools && make get_vendor_deps && make install
3. Welcome!
Let’s use the Cosmos-SDK
To make a
Blockchain
Replicated State Machine
Hi, I’m Jack ✌
4. Replicated State Machine
What is the initial state?
What are the possible state transitions?
Is it Byzantine Fault Tolerant?
5. Cosmos Developer Kit
Golang toolset for building Replicated State Machines
Ruby-on-Rails for Blockchain
Focus on the Application
Proof-of-Stake 🍃 is better than Proof-of-Work ☠🔥
Tendermint for Consensus & Networking
6. Our Application!
Distributed Name Service
No one should be able to limit access to a public utility
Distribute the access and responsibility
● Ethereum Name Service
● Handshake
● Namecoin/Blockstack
8. The SDK is a Modular Framework
● Aggregates a collection of interoperable modules
● Each Module has its own Message/Transaction processor
● The SDK routes each message to the respective module
9. Modules in this Tutorial
● Auth
○ Access Control List (ACL) with Asymmetric Encryption
● Bank
○ Money Money Money
● NameService
○ Whois???
10. Modules NOT in this Tutorial
● Staking
○ Used for updating the set of validators
○ We use a fixed set from genesis
○ Private => Permissioned => Public
● Governance
○ Let’s Vote!
12. Modules: State
● All state goes in one store called multistore
● Contains multiple key/value stores called KVStores
● Our State
○ Accounts (auth)
○ Balances (bank)
○ Domain Names (nameservice)
13. Domain Names: nameStore
● Name => Value
○ What does the name resolve to (the zonefile)?
● Name => Owner
○ Who owns the name?
● Name => Price
○ How much to buy it?
14. Modules: Messages
● Messages Trigger State Transitions
● The Module Routes the Messages to Handlers
● The Handlers Hand them to Keepers
● The Keepers update the State
15. Domain Names: Messages
● MsgSetName
○ This message allows an owner to set the value of a name
● MsgBuyName
○ This message allows anyone to buy a name for some price
16. General Flow
● A Transaction contains a Message
● Tendermint nodes receive Transactions in Blocks
● They’re passed to the application via ABCI
○ Application Blockchain Interface
○ Socket Protocol between Tendermint and the application
● Decoded as Messages by baseapp & routed to correct Module
● Each Module has Handlers that decides what to do with them
● Each Handler calls Keepers to update the State
17. Let’s begin in ./app.go
● Imports
○ Log - for logs
○ Auth - for accounts and signing
○ Dbm - tendermint database
○ Codec - serialization
○ Baseapp - boilerplate
● Makes a new Type called nameservice
○ That’s our app!
18. Let’s begin in ./app.go
● Imports
○ Log - for logs
○ Auth - for accounts and signing
○ Dbm - tendermint database
○ Codec - serialization
○ Bam - Baseapp boilerplate
● Makes a new Type called nameservice
○ That’s our app!
19. Our nameservice module
● All modules go in the directory called ./x/
● Our module goes in the directory called ./x/nameservice/
● Inside ./x/nameservice/ we’ll have:
○ Handler.go
○ Keeper.go
○ Querier.go
○ Msgs.go
○ Codec.go
○ Client/ => for REST & CLI
20. ● Keepers manage the state
○ Like reducers/redux or mutations/vuex
● Handlers call the Keepers
○ Like actions in redux/vuex
The Keeper
21. ● nameStoreKey
○ map[name]value - like a Zonefile w traditional DNS
● ownerStoreKey
○ map[sdk_address]name - who owns what
● priceStoreKey
○ map[name]price - how much a name costs
Our Keeper has 3 New Keys
24. Msgs & Handlers
● Msgs trigger Handlers
○ Like user initiated events
● Handlers call the Keepers
○ Like actions in redux/vuex
● Keepers manage the state
○ Like reducers/redux or mutations/vuex
32. Codec
● Register new msg types for serialization (not whois?)
● Amino is an extension of protobuf
● Goes in ./x/nameservice/codec.go
33. Building Clients!
● From the Command Line
○ Utilizes the cobra library
○ Goes in ./x/nameservice/client/cli/query.go
○ Goes in ./x/nameservice/client/cli/tx.go
● From a REST server
○ Goes in ./x/nameservice/client/rest/rest.go
● Export both from Module Client
○ Goes in ./x/nameservice/client/module_client.go
34. Pull it all back into app.go
● Import and Initialize all our new pieces
● AddRoute for Handlers and Queriers
● Register the Codecs
● InitChainer for initial application state
○ Takes a genesis.json file that can be generated by the CLI
○ This is where I’ll add everyone’s public key and some
balance of token for buying names $ )
35. Build our Binaries!
● Wrap our app with commands we can use
● Wrap our client with commands we can use
● ./cmd/nsd/main.go
○ Name Service Daemon runs our node
● ./cmd/nscli/main.go
○ Name Service CLI
36. One last step
● Makefile
○ Installs and builds
● Gopkg
○ keeps our versions constrained
● Build!
○ dep ensure -update -v
○ make install