cosmos-sdk/docs/sdk/gaiacli.md

4.7 KiB

Gaia CLI

gaiacli is the command line interface to manage accounts and transactions on Cosmos testnets. Here is a list of useful gaiacli commands, including usage examples.

Key Types

There are three types of key representations that are used:

  • cosmosaccaddr

    • Derived from account keys generated by gaiacli keys add
    • Used to receive funds
    • e.g. cosmosaccaddr15h6vd5f0wqps26zjlwrc6chah08ryu4hzzdwhc
  • cosmosaccpub

    • Derived from account keys generated by gaiacli keys add
    • e.g. cosmosaccpub1zcjduc3q7fu03jnlu2xpl75s2nkt7krm6grh4cc5aqth73v0zwmea25wj2hsqhlqzm
  • cosmosvalpub

    • Generated when the node is created with gaiad init.
    • Get this value with gaiad tendermint show_validator
    • e.g. cosmosvalpub1zcjduc3qcyj09qc03elte23zwshdx92jm6ce88fgc90rtqhjx8v0608qh5ssp0w94c

Generate Keys

You'll need an account private and public key pair a.k.a. `sk, pk` respectively to be able to receive funds, send txs, bond tx, etc.

To generate a new key default _ed25519_ elliptic curve:

gaiacli keys add <account_name>

Next, you will have to create a passphrase to protect the key on disk. The output of the above command will contain a seed phrase. Save the seed phrase in a safe place in case you forget the password!

If you check your private keys, you'll now see <account_name>:

gaiacli keys show <account_name>

You can see all your available keys by typing:

gaiacli keys list

View the validator pubkey for your node by typing:

gaiad tendermint show_validator

::: danger Warning We strongly recommend NOT using the same passphrase for multiple keys. The Tendermint team and the Interchain Foundation will not be responsible for the loss of funds. :::

Get Tokens

The best way to get tokens is from the Cosmos Testnet Faucet. If the faucet is not working for you, try asking #cosmos-validators. The faucet needs the cosmosaccaddr from the account you wish to use for staking.

After receiving tokens to your address, you can view your account's balance by typing:

gaiacli account <account_cosmosaccaddr>

::: warning Note When you query an account balance with zero tokens, you will get this error: No account with address <account_cosmosaccaddr> was found in the state. This can also happen if you fund the account before your node has fully synced with the chain. These are both normal.

We're working on improving our error messages! :::

Send Tokens

gaiacli send \
  --amount=10faucetToken \
  --chain-id=gaia-6002 \
  --name=<key_name> \
  --to=<destination_cosmosaccaddr>

::: warning Note The --amount flag accepts the format --amount=<value|coin_name>. :::

Now, view the updated balances of the origin and destination accounts:

gaiacli account <account_cosmosaccaddr>
gaiacli account <destination_cosmosaccaddr>

You can also check your balance at a given block by using the --block flag:

gaiacli account <account_cosmosaccaddr> --block=<block_height>

Delegate

On the upcoming mainnet, you can delegate atom to a validator. These delegators can receive part of the validator's fee revenue. Read more about the Cosmos Token Model.

Bond Tokens

On the testnet, we delegate steak instead of atom. Here's how you can bond tokens to a testnet validator:

gaiacli stake delegate \
  --amount=10steak \
  --address-validator=$(gaiad tendermint show_validator) \
  --from=<key_name> \
  --chain-id=gaia-6002

While tokens are bonded, they are pooled with all the other bonded tokens in the network. Validators and delegators obtain a percentage of shares that equal their stake in this pool.

::: tip Note Don't use more steak thank you have! You can always get more by using the Faucet! :::

Unbond Tokens

If for any reason the validator misbehaves, or you want to unbond a certain amount of tokens, use this following command. You can unbond a specific amount ofshareseg:`12.1` or all of them `MAX`.

gaiacli stake unbond begin \
  --address-validator=$(gaiad tendermint show_validator) \
  --shares-percent=1 \
  --from=<key_name> \
  --chain-id=gaia-6002

Later you must use the gaiacli stake unbond complete command to finish unbonding at which point you can can check your balance and your stake delegation to see that the unbonding went through successfully.

gaiacli account <account_cosmosaccaddr>

gaiacli stake delegation \
  --address-delegator=<account_cosmosaccaddr> \
  --address-validator=$(gaiad tendermint show_validator) \
  --chain-id=gaia-6002