Coder Social home page Coder Social logo

cosmos-local-testnet's Introduction

Cosmos Testnet Tutorial

1. Prerequisites

Ignite CLI

2. Initialize your chain

Create a binary in your terminal:

ignite scaffold chain <application-name>

Build the application chain:

cd <application-name>
ignite chain build

3. Create keys for your nodes

Cosmos SDK will automatically create a binary cli, and we can use it as a command: appd

appd keys add <key-name-1>
appd keys add <key-name-2>
...

4. Initialize chain nodes

appd init <moniker1> --home <addr-1> --chain-id <your-chain-id>
appd init <moniker2> --home <addr-2> --chain-id <your-chain-id>
...

5. Add genesis accounts

appd add-genesis-account $(appd keys show <key-name-1> -a) <amount>stake --home <addr-1>
appd add-genesis-account $(appd keys show <key-name-2> -a) <amount>stake --home <addr-1>
...

6. Stake into the chain

appd gentx <key-name-1> <amount>stake --chain-id <your-chain-id> --home <addr-1>
appd collect-gentxs --home <addr-1>

7. Start the chain node

Before you start, the api server and swagger should be enabled. You can go to the app.toml to change these. Then:

appd start --home <addr-1>

8. Config the next chain node to sync with the blockchain

Go to the folders that contain the config and data directory of the chains:

cd <addr-2>

Copy these files of the first chain into the config folder:

  • genesis.json
  • app.toml
  • client.toml
  • config.toml

Change every ports in these 3 .toml files to differ from the first chain.

You also need to add the seeds and the persistent_peers:

seeds="<node-id-1>@<listen-addr>:<port>,<node-id-1>@<listen-addr>:<port>"
persistent_peers="<node-id-1>@<listen-addr>:<port>,<node-id-1>@<listen-addr>:<port>"

To get the node id, run this command:

appd tendermint show-node-id

After everything is done, you can start the node with:

appd start <addr-2>

NOTE: in local development, if using 127.0.0.1 and the node throws an error, you can try localhost` instead.

9. Run the node as a validator

Before sending the create-validator transaction, you need to send some tokens from the existing validator to the new ones. Run this command:

appd q account <account-addr> --chain-id testnet --home <home-dir>

You might see an error is thrown saying that the account is not found. This problem may occur if the account was created on a different node or on a different chain with a different chain ID. When querying for an account, the node will look for the account's address in its local state database. If the account was not created on that node or chain, then the node will not have the account's address in its local state database and will return an error.

To solve this problem, you can send tokens from the existing validator to the new ones, so that the validator can recognize your new account address. Run this command:

appd tx bank send <account-addr> <amount>stake --chain-id testnet --home <home-dir>

Now you can run the previous command to check the balance of the account.

Create a staking transaction by running:

appd tx staking create-validator \                          
  --amount=<amount>stake \
  --pubkey=$(appd tendermint show-validator --home <addr-2>) \
  --moniker=<moniker2> \
  --chain-id=<your-chain-id> \
  --commission-rate="0.10" \
  --commission-max-rate="0.20" \
  --commission-max-change-rate="0.01" \
  --min-self-delegation="1000000" \
  --gas="auto" \
  --from=<key-name-2> --home <addr-2>

Restart the node, and you will have another validator.

You can check the status of all validators with:

appd tendermint show-validator --home <addr-2>

or with:

appd q staking validator cosmosvaloper1yourvalidatoraddress --chain-id=testnet --node=tcp://127.0.0.1:26657

If the status of the validator is BOND_STATUS_UNBONDED, you might need to delegate more tokens, you can run:

appd tx staking delegate <account-addr> <amount>stake --chain-id testnet --home <home-dir>

If the status of the validator is BOND_STATUS_BONDED, then congrats, you have a new validator for your network.

cosmos-local-testnet's People

Contributors

nvtrinh2001 avatar

Stargazers

Duc Minh avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.