SlideShare a Scribd company logo
Cosmos-SDK
Talkshop
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
Welcome!
Let’s use the Cosmos-SDK
To make a
Blockchain
Replicated State Machine
Hi, I’m Jack ✌
Replicated State Machine
What is the initial state?
What are the possible state transitions?
Is it Byzantine Fault Tolerant?
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
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
Our Application!
● github.com/cosmos/sdk-application-tutorial
● Download the tutorial to follow along with code
● At the end I’ll spin up a node and give everyone money
● You can create and buy names from each other
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
Modules in this Tutorial
● Auth
○ Access Control List (ACL) with Asymmetric Encryption
● Bank
○ Money Money Money
● NameService
○ Whois???
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!
Modules are States & Messages
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)
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?
Modules: Messages
● Messages Trigger State Transitions
● The Module Routes the Messages to Handlers
● The Handlers Hand them to Keepers
● The Keepers update the State
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
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
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!
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!
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
● Keepers manage the state
○ Like reducers/redux or mutations/vuex
● Handlers call the Keepers
○ Like actions in redux/vuex
The Keeper
● 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
● Getters
○ ResolveName
○ HasOwner
○ GetOwner
○ GetPrice
● Setters
○ SetName
○ SetOwner
○ SetPrice
Our Keeper has Getters & Setters
Our Keeper has Getters & Setters
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
Msgs go in ./x/nameservice/msgs.go
Two Msg Types Needed For Our App
● MsgSetName
○ Owners can set the name
● MsgBuyName
○ Names can be bought
MsgSetName
● Set all the Interfaces
● Example: ValidateBasic
handleMsgSetName
● Goes in ./x/nameservice/handler.go
● Utilizes the Keeper we made earlier
Queriers
● Queriers : Getters
● Handlers : Setters
● Goes inside ./x/nameservice/querier.go
● Uses the Keeper to access the KVStore
Our Queriers
● Resolve
○ Accepts name returns value
● Whois
○ Accepts name returns value, price, owner
Our Queriers: Whois
Codec
● Register new msg types for serialization (not whois?)
● Amino is an extension of protobuf
● Goes in ./x/nameservice/codec.go
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
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 $ )
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
One last step
● Makefile
○ Installs and builds
● Gopkg
○ keeps our versions constrained
● Build!
○ dep ensure -update -v
○ make install
Claim Your Name!
Go to talkshop.name/

More Related Content

PPTX
Apache Superset - open source data exploration and visualization (Conclusion ...
PPTX
Diabetes Mellitus
PPTX
Hypertension
PPTX
Republic Act No. 11313 Safe Spaces Act (Bawal Bastos Law).pptx
PPTX
Power Point Presentation on Artificial Intelligence
PDF
Caça palavras - Bullying
PPTX
Apache Superset - open source data exploration and visualization (Conclusion ...
Diabetes Mellitus
Hypertension
Republic Act No. 11313 Safe Spaces Act (Bawal Bastos Law).pptx
Power Point Presentation on Artificial Intelligence
Caça palavras - Bullying

What's hot (20)

PDF
Tendermint/Cosmos: Many Chains, Many Tokens, One Ecosystem
PDF
Building a blockchain on tendermint
PPSX
Cosmos-Sdk Presentation
PPTX
Non-fungible tokens (nfts)
PPTX
Blockchain Intro to Hyperledger Fabric
PDF
Blockchain
PDF
Ethermint 2.0: An Ethereum Scaling Solution by Cosmos
PDF
Blockchain Introduction
PPTX
Introduction to Bitcoins and Cryptocurrency
PDF
Introduction To Solidity
PDF
Introduction to Ethereum
PDF
The Bitcoin Lightning Network
PDF
Crypto currency
PDF
Blockchain & the IoT
PPTX
what is bitcoin, its history and detail
PDF
Blockchain Security Issues and Challenges
PDF
An Introduction to Blockchain
PDF
Smart contracts & dApps
ODP
Overview of ZeroMQ
PPTX
Introduction to Blockchain and Smart Contracts
Tendermint/Cosmos: Many Chains, Many Tokens, One Ecosystem
Building a blockchain on tendermint
Cosmos-Sdk Presentation
Non-fungible tokens (nfts)
Blockchain Intro to Hyperledger Fabric
Blockchain
Ethermint 2.0: An Ethereum Scaling Solution by Cosmos
Blockchain Introduction
Introduction to Bitcoins and Cryptocurrency
Introduction To Solidity
Introduction to Ethereum
The Bitcoin Lightning Network
Crypto currency
Blockchain & the IoT
what is bitcoin, its history and detail
Blockchain Security Issues and Challenges
An Introduction to Blockchain
Smart contracts & dApps
Overview of ZeroMQ
Introduction to Blockchain and Smart Contracts
Ad

Similar to Cosmos SDK Workshop: How to Build a Blockchain from Scratch (20)

PDF
Secure Developer Access at Decisiv
PPTX
Chaincode Use Cases
PDF
Idempotency of commands in distributed systems
PDF
Guvnor presentation jervis liu
PDF
Future of Cloud Computing with Containers
PDF
Crikeycon 2019 Velociraptor Workshop
PDF
Introduction to Jhipster
PDF
Digital Forensics and Incident Response in The Cloud Part 3
PPTX
Ultimate Guide to Microservice Architecture on Kubernetes
PDF
Microservices development at scale
PDF
An approach to responsive, realtime with Backbone.js and WebSockets
PPTX
Truemotion Adventures in Containerization
PDF
Swarm: Native Docker Clustering
PPTX
WebSDK - Switching between service providers
PDF
Introduction to PaaS and Heroku
PPTX
Introduction to kubernetes
PDF
202107 - Orion introduction - COSCUP
PDF
Heroku to Kubernetes & Gihub to Gitlab success story
PDF
Docker and Your Path to a Better Staging Environment - webinar by Gil Tayar
PDF
JSFest 2019: Technology agnostic microservices at SPA frontend
Secure Developer Access at Decisiv
Chaincode Use Cases
Idempotency of commands in distributed systems
Guvnor presentation jervis liu
Future of Cloud Computing with Containers
Crikeycon 2019 Velociraptor Workshop
Introduction to Jhipster
Digital Forensics and Incident Response in The Cloud Part 3
Ultimate Guide to Microservice Architecture on Kubernetes
Microservices development at scale
An approach to responsive, realtime with Backbone.js and WebSockets
Truemotion Adventures in Containerization
Swarm: Native Docker Clustering
WebSDK - Switching between service providers
Introduction to PaaS and Heroku
Introduction to kubernetes
202107 - Orion introduction - COSCUP
Heroku to Kubernetes & Gihub to Gitlab success story
Docker and Your Path to a Better Staging Environment - webinar by Gil Tayar
JSFest 2019: Technology agnostic microservices at SPA frontend
Ad

More from Tendermint Inc (10)

PDF
Vision of Rearchitecting the Blockchain Ecosystem by Chjango Unchained
PPTX
Many Chains, Many Tokens, One Ecosystem
PDF
Open Finance & the Decentralization Movement
PDF
Introduction to Blockchain & Building the 3rd Generation with Golang
PDF
Interblockchain Communication for Blockchain Interoperability
PDF
A Brief History of Distributed State
PDF
Code Run of the Cosmos SDK
PDF
Intro to the Cosmos Network
PDF
Four Dimensional Blockchain Scaling
PPTX
Cosmos Proof-of-Stake: An Introduction
Vision of Rearchitecting the Blockchain Ecosystem by Chjango Unchained
Many Chains, Many Tokens, One Ecosystem
Open Finance & the Decentralization Movement
Introduction to Blockchain & Building the 3rd Generation with Golang
Interblockchain Communication for Blockchain Interoperability
A Brief History of Distributed State
Code Run of the Cosmos SDK
Intro to the Cosmos Network
Four Dimensional Blockchain Scaling
Cosmos Proof-of-Stake: An Introduction

Recently uploaded (20)

PPTX
Modernising the Digital Integration Hub
PDF
DP Operators-handbook-extract for the Mautical Institute
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
PDF
A review of recent deep learning applications in wood surface defect identifi...
PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
PDF
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
PDF
Enhancing emotion recognition model for a student engagement use case through...
PDF
August Patch Tuesday
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PDF
Hybrid model detection and classification of lung cancer
PPTX
The various Industrial Revolutions .pptx
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
PDF
CloudStack 4.21: First Look Webinar slides
PDF
sustainability-14-14877-v2.pddhzftheheeeee
PDF
Taming the Chaos: How to Turn Unstructured Data into Decisions
PDF
Getting Started with Data Integration: FME Form 101
PDF
Hindi spoken digit analysis for native and non-native speakers
PPTX
Web Crawler for Trend Tracking Gen Z Insights.pptx
PPT
What is a Computer? Input Devices /output devices
PDF
Getting started with AI Agents and Multi-Agent Systems
Modernising the Digital Integration Hub
DP Operators-handbook-extract for the Mautical Institute
Final SEM Unit 1 for mit wpu at pune .pptx
A review of recent deep learning applications in wood surface defect identifi...
A contest of sentiment analysis: k-nearest neighbor versus neural network
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
Enhancing emotion recognition model for a student engagement use case through...
August Patch Tuesday
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
Hybrid model detection and classification of lung cancer
The various Industrial Revolutions .pptx
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
CloudStack 4.21: First Look Webinar slides
sustainability-14-14877-v2.pddhzftheheeeee
Taming the Chaos: How to Turn Unstructured Data into Decisions
Getting Started with Data Integration: FME Form 101
Hindi spoken digit analysis for native and non-native speakers
Web Crawler for Trend Tracking Gen Z Insights.pptx
What is a Computer? Input Devices /output devices
Getting started with AI Agents and Multi-Agent Systems

Cosmos SDK Workshop: How to Build a Blockchain from Scratch

  • 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
  • 7. Our Application! ● github.com/cosmos/sdk-application-tutorial ● Download the tutorial to follow along with code ● At the end I’ll spin up a node and give everyone money ● You can create and buy names from each other
  • 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!
  • 11. Modules are States & Messages
  • 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
  • 22. ● Getters ○ ResolveName ○ HasOwner ○ GetOwner ○ GetPrice ● Setters ○ SetName ○ SetOwner ○ SetPrice Our Keeper has Getters & Setters
  • 23. Our Keeper has Getters & Setters
  • 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
  • 25. Msgs go in ./x/nameservice/msgs.go
  • 26. Two Msg Types Needed For Our App ● MsgSetName ○ Owners can set the name ● MsgBuyName ○ Names can be bought
  • 27. MsgSetName ● Set all the Interfaces ● Example: ValidateBasic
  • 28. handleMsgSetName ● Goes in ./x/nameservice/handler.go ● Utilizes the Keeper we made earlier
  • 29. Queriers ● Queriers : Getters ● Handlers : Setters ● Goes inside ./x/nameservice/querier.go ● Uses the Keeper to access the KVStore
  • 30. Our Queriers ● Resolve ○ Accepts name returns value ● Whois ○ Accepts name returns value, price, owner
  • 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
  • 37. Claim Your Name! Go to talkshop.name/