Key management

Generate new key

To generate new key, use the following command:

swisstronikcli keys add <key_name>

If you got an error "Error: provided algorithm "eth_secp256k1" is not supported", specify an additional parameter for keyring --keyring-backend test or --keyring-backend file

NOTE: This command will generate a mnemonic for a new key, therefore, you should save it in a secure place.

The command above will output the following:

- address: swtr156pzc2rj2xka9cu0gpgkmz3vmal544nlu9mwj7
  name: debug
  pubkey: '{"@type":"/ethermint.crypto.v1.ethsecp256k1.PubKey","key":"AyJHdeTNCnjV4v5ZJEbyFS5UtzBQk1ThkZB4G7QR3Cb6"}'
  type: local


**Important** write this mnemonic phrase in a safe place.
It is the only way to recover your account if you ever forget your password.

picnic explain flower snack lava town marriage search approve increase display angry express peanut peanut mouse noise knock address situate hope pelican advance rather

Restore key from mnemonic

If you got error "Error: provided algorithm "eth_secp256k1" is not supported", specify an additional parameter for keyring --keyring-backend test or --keyring-backend file

If you already have a mnemonic and want to restore a key from it, use the following command:

swisstronikcli keys add <key_name> --recover

It will prompt you for your mnemonic. Once you input your mnemonic, your output should look like:

- address: swtr156pzc2rj2xka9cu0gpgkmz3vmal544nlu9mwj7
  name: debug
  pubkey: '{"@type":"/ethermint.crypto.v1.ethsecp256k1.PubKey","key":"AyJHdeTNCnjV4v5ZJEbyFS5UtzBQk1ThkZB4G7QR3Cb6"}'
  type: local

List all accounts

To show all stored accounts, use the following command:

swisstronikcli keys list

This command should output the following:

- address: swtr156pzc2rj2xka9cu0gpgkmz3vmal544nlu9mwj7
  name: debug
  pubkey: '{"@type":"/ethermint.crypto.v1.ethsecp256k1.PubKey","key":"AyJHdeTNCnjV4v5ZJEbyFS5UtzBQk1ThkZB4G7QR3Cb6"}'
  type: local

If you cannot find your key in the output, try to specify --keyring-backend test or --keyring-backend file

Export ETH private key

Since swisstronikcli operates with eth_secp256k1 private keys, all keys stored in the keyring are Ethereum-compatible private keys. You can export Ethereum private key (for example, to use it in MetaMask) by using the following command:

swisstronikcli keys unsafe-export-eth-key <key_name>

If you encounter the error "Error: <wallet_name>.info: key not found", try specifying either --keyring-backend test or --keyring-backend file

The command above should output your Ethereum private key, for example:

C66DB5D865EEF076B638AEA46445775989C7B0B88805CB6A70AF37523DC2672D

Convert address

swisstronikcli can work only with bech32-encoded (swtr1) addresses, so if you want to convert your Ethereum address to bech32 format (and vice versa), you can use the following command:

swisstronikcli debug convert-address <bech32-or-eth-address>

It should output the converted address:

Address bytes: [166 130 44 40 114 81 173 210 227 143 64 81 109 138 44 223 127 74 214 127]
Address (hex): A6822C287251ADD2E38F40516D8A2CDF7F4AD67F
Address (EIP-55): 0xA6822c287251ADd2E38F40516D8a2cDF7F4aD67f
Bech32 Acc: swtr156pzc2rj2xka9cu0gpgkmz3vmal544nlu9mwj7
Bech32 Val: swtrvaloper156pzc2rj2xka9cu0gpgkmz3vmal544nlhg5v7r

Last updated