The Cosmos SDK repository contains a folder called simapp(opens new window). In this folder you can find the code to run a simulated version of the Cosmos SDK, so you can test commands without actually interacting with your chain. The binary is called simd and you will be using it to interact with your node.
First, create and change the directory into a cosmos folder, and then clone the cosmos-sdk repo into that folder:
$ mkdir cosmos
$ cd cosmos
$ git clone https://github.com/cosmos/cosmos-sdk
$ cd cosmos-sdk
Make sure you are using the same version used at the time of writing:
$ git checkout v0.42.6
Then build cosmos-sdk:
$ make build
The build takes a few minutes and creates a build folder and a simapp binary named simd:
You can find your chain_id in your output, which in our build happens to be called test-chain-rT4wZY. Make a note of your output's name, as you will need it later to determine the chain ID by passing it to simapp via the flag --chain-id.
You can also inspect your keys. These are held in the backend keyring, which by default is that of the operating system:
$ ./simd keys list
As you might have expected, you do not have any keys yet:
Now you can add a new key:
$ ./simd keys add b9lab
Which prints something similar to:
- name: b9lab
**Important:** write this mnemonic phrase in a safe place. It is the only way to recover your account if you ever forget your password.
ivory uniform actual spot floor vessel monster rose yellow noise smile odor veteran human reason miss stadium phrase assault puzzle sentence approve coral apology
You can see the mnemonic at the end of the above output. This sequence of words is a mnemonic that you can use to recover your public and private keys. In a production setting, the mnemonic must be stored in a reliable and confidential fashion as part of the key-management infrastructure.
As previously explained, a Cosmos SDK blockchain relies on identified validators to produce blocks. Initially there is no validator to generate blocks. You are in a catch-22 situation: your initialized and unstarted chain needs a genesis account and validator for bootstrapping purposes.
Make your key, also known as an account, have an initial balance in the genesis file:
Appended here to the amount is the stake suffix. This stake represents the unit for the tokens in this chain as per the genesis file. Therefore, this command adds 100000000stake to your account. If in doubt, you can confirm the proper suffix in the genesis.json file with:
$ grep -A 2 -B 2 denom ~/.simapp/config/genesis.json
You can also confirm in the genesis file itself that you have an initial balance:
$ grep -A 10 balances ~/.simapp/config/genesis.json
Despite this initial balance, before you run your blockchain you still need to escape the catch-22 and include your bootstrap transactions in the genesis file.
In this scenario, for your network to even run, you must meet the 2/3 threshold of the weighted validators.
However you will be alone on the network, so you can stake any number at or above the minimum enforced(opens new window), i.e. 1000000stake. However, to remind yourself that it is important that honest nodes stake a large amount, you stake 70000000stake of your 100000000stake in the b9lab account you just created. Make sure to not use all of your tokens so you can still pay for gas and so you don't run out of tokens later.
Practice sending a transaction. To do this, you are going to create another account named "student" and transfer some tokens to that account:
$ ./simd keys add student
- name: student
**Important** record this mnemonic phrase in a safe place. It is the only way to recover your account if you ever forget your password.
gown all scissors page panel table hill acoustic junior run winter cement mass clump moon adjust glare never satoshi easily illness hip rib multiply
Before sending any tokens confirm that the balance of the new account is absent:
$ ./simd query bank balances $(./simd keys show student -a)
This account does not have a balance. The new account does not yet exist in your blockchain. Only the key pair has been generated and stored in your keyring:
The modules in the /cosmos-sdk/x/ folder are maintained by several organisations working on the Cosmos stack. To understand a module, the best way is to have a look at the respective spec folder. For example, look at the cosmos-sdk/x/bank/spec/01_state.md(opens new window) to understand the state of the bank module which you used in this section.
How to run and to interact with a blockchain by using simapp, which contains the code necessary to run a simulated version of the Cosmos SDK called simd so you can test commands without actually interacting with your chain.
How to compile and initialize simapp, and to inspect the initial configuration of your chain's genesis state.
How to prepare your account, including how to add, confirm, and inspect your keys, and review your mnemonic.
How to make yourself a proper validator, by adding and confirming the presence of an initial balance and including bootstrap transactions in the genesis file.
How to start your single-node blockchain, observe blocks being created through the terminal window, and check the balances.
How to practice sending transactions by creating another account and transferring tokens to it, and checking the balance of the new account to confirm the successful transfer.
CLI routing with the examination of the initial Go code, revealing various aspects of your nascent chain.
† This website is maintained by the Interchain Foundation (ICF). The contents and opinions of this website are those of the ICF. The ICF provides links to cryptocurrency exchanges as a service to the public. The ICF does not warrant that the information provided by these websites is correct, complete, and up-to-date. The ICF is not responsible for their content and expressly rejects any liability for damages of any kind resulting from the use, reference to, or reliance on any information contained within these websites.