read.cash Log in
@zh edited

BloChaDev - Cosmos SDK

Next article in my BlockChain Development series. It is a logical extension on the previous article about Tendermint Core. If you remember Tendermint core give you a **ready to go state-machine replication engine** a.k.a blockchain. Great foundation, but coding actual state machines on top of it is not so easy. And in fact it is not the job for any core to do this. https://read.cash/@zh/blochadev-tendermint-core-853514f1

Here the Cosmos project comes. The project describes itself as *"...a decentralized network of independent parallel blockchains, each powered by BFT consensus algorithms like* *Tendermint* *consensus...".* They have very active OSS development - **more then 40 active repositories** on GitHub! It is impossible to talk about all of them in one article so lets mention just some more popular ones: https://cosmos.network/ https://cosmos.network/intro#what-is-tendermint-core-and-the-abci https://github.com/cosmos/ Gaia - Cosmos Hub - *"...allow fully sovereign blockchains to interact with one another using a protocol called* *IBC**..."* https://github.com/cosmos/gaia/ https://github.com/cosmos/ics/tree/master/ibc Scaffold - *Scaffolding for Cosmos-SDK based application* https://github.com/cosmos/scaffold/ Cosmos-SDK - *A Framework for Building High Value Public Blockchains* https://github.com/cosmos/cosmos-sdk/ Ethermint - *Ethereum on Tendermint using Cosmos-SDK* https://github.com/cosmos/ethermint Scaffold **Main programming language**: Go Project web page https://cosmos.network/sdk Documentation pages https://docs.cosmos.network/ Github Repository https://github.com/cosmos/scaffold For people coming from the Rails development background *scaffold* is the same as *rails scaffold* utility - creating a boilerplate of models, views and controllers code (named here Keepers, Handlers etc.). Some times good to start with, but some times too generic and too much changes needed. Mixed fillings on this one... Cosmos SDK tutorials suggesting starting from the *nameservice* example and more specifically starting with the scaffold tool , so I tried first: https://tutorials.cosmos.network/ https://tutorials.cosmos.network/nameservice/tutorial/02-app-init.html $ scaffold app lvl-1 zh hello_cosmos $ cd hello_cosmos # for some reason need to remove -mod=readonly in the Makefile # because of: go: updates to go.sum needed, disabled by -mod=readonly $ make Good! Compilation gave me two binaries installed in *$GOLANG/bin/* directory, so I can start them directly and check the available options: $ appd $ appcli Names of the binaries can be changed and will be different for the different projects. ***appd*** is a very thin wrapper around *tendermint* daemon starting command. ***appcli*** is a wrapper around *abci-cli* for sending commands to that daemon. Still not too much as a functionality added to the tendermint, basically same options can be used - *init*, *tx*, *query* etc., but it so much more convenient now: different daemon and cli names for every project, different config directories ( *~/.appd/* and *~/.appcli/ on OS X*) for different projects etc. The interesting part begins, when you start adding custom modules. They will add / change behaviour of the basic commands, usually adding some subcommands to them: $ cd x/ $ scaffold module zh hello_cosmos nameservice I added the new module, but as I mentioned above scaffold is too generic - a lot of changes needed to make this module really doing something useful. So I started changing different files, following the tutorial, but they lost me somewhere in the middle... To much was going on... And I'm lazy... Started searching for an easier way... And DA-DA-AAAA - found SDK Tutorials repo - all of the tutorials code, already finished! Nice. So I small tip: https://github.com/cosmos/sdk-tutorials **Do not start with scaffolding, clone** **SDK tutorials** and start studing / changing already working code - manual suggesting nameservice or scavenge. https://github.com/cosmos/sdk-tutorials/tree/master/nameservice https://github.com/cosmos/sdk-tutorials/tree/master/scavenge Cosmos SDK *A Framework for Building High Value Public Blockchains* **Main programming language**: Go GitHub repository https://github.com/cosmos I want to talk more also about **Cosmos SDK** *(maybe in separate article...)*, because it is the real **mother of dragons**, producing more and more awesome new tools. When some of them became too big, they usually move it to a separate repository as the Gaia Hub, mentioned above. Just look on the modules directory ! Real code treasure: https://github.com/cosmos/cosmos-sdk/tree/master/x A**uth** - *Authentication of accounts and transactions for Cosmos SDK application* https://github.com/cosmos/cosmos-sdk/blob/master/x/auth/spec/README.md Bank - *Token transfer functionalities* https://github.com/cosmos/cosmos-sdk/blob/master/x/bank/spec/README.md Staking - *Proof-of-stake layer for public blockchains* https://github.com/cosmos/cosmos-sdk/blob/master/x/staking/spec/README.md Mint - *Creation of new units of staking token* https://github.com/cosmos/cosmos-sdk/blob/master/x/mint/spec/README.md Your own CryptoCoin in less than 5 min SDK hellochain tutorial mentioning, that this example is broken, so I extracted the essential parts of it in a separate repository, something between *scaffold* and *hellochain*: https://github.com/cosmos/sdk-tutorials/tree/master/hellochain/tutorial More then scaffold - the starter part, providing creating users and coin exchange Less then *hellochain* SDK tutorial - no greeter module $ git clone https://github.com/zh/hw_chain.git $ cd hw_chain $ make $ ./init.sh # create and provision two users - test1 and test2 ... "name": "test1", "type": "local", "address": "cosmos1n80wglue... ... $ hwd start ...starting ABCI with Tendermint module=main Done. You have running blockchain and you can exchange **HelloWorldCoin (HWC)** on top of it: Get user test1 balance $ hwcli query account $(hwcli keys show test1 -a) ..."address": "cosmos1n80wglue8uepm06axpqj69l6q0jmjemantu4fh", "coins": [ { "denom": "hwc", "amount": "1000000" }, ... Get user test2 balance $ hwcli query account $(hwcli keys show test2 -a) ... "coins": [ { "denom": "hwc", "amount": "1000" }, ... User test1 sending 50 HWC to user test2 (transaction with confirmation) $ hwcli tx send $(hwcli keys show test1 -a) $(hwcli keys show test2 -a) 50hwc ... "msgs": [ { ... "amount": [ { "denom": "hwc", "amount": "50" } confirm transaction before signing and broadcasting [y/N]: y { ... "txhash": "E701569...", ... } $ hwcli query account $(hwcli keys show test2 -a) # get user test2 balance ... "coins": [ { "denom": "hwc", "amount": "1050" }, Summary **Cosmos** is a modern and very active project. A lot of great stuff coming almost every day from them: connecting different blockchains, game of zones etc. It is a real pleasure to use their SDK. With Tendermint for the state-machine replication engine and Cosmos SDK for building secure blockchain applications the possibilities are endless. For recent news follow Cosmos on twitter, reddit or sign on for their newsletter. https://twitter.com/cosmos https://www.reddit.com/r/cosmosnetwork/ https://cosmos.network/newsletters/signup/cosmos Additional information Cosmos / Tendermint explained for real idiots https://medium.com/coinmonks/cosmos-tendermint-explained-for-real-idiots-ab4305cbb41 DApps and Blockchains in the Cosmos Ecosystem https://medium.com/stakin/dapps-and-blockchains-built-on-the-cosmos-ecosystem-31731494570b 5 Differences between Cosmos & Polkadot https://medium.com/@juliankoh/5-differences-between-cosmos-polkadot-67f09535594b Build 2 Blockchains and connect them via IBC ATOM guide https://medium.com/@meleacrypto/build-2-blockchains-and-connect-them-via-ibc-atom-guide-1753f02763a7 Cosmos Tamagochi Zone https://stake.fish/en/goz/ *Coming next: Hm,... still not sure, maybe* *Zilliqa* *or* *Polkadot* *...* https://dev.zilliqa.com/en/ https://polkadot.network/ *P.S. I know I will not become rich, writing these articles, but contributing a small amount of BCH will be hugely appreciated*, *will support my work and keep me going.*

No comments yet

Log in to join in Reading is open to everyone. Replying needs an account.