Zwallet Operations

Global Parameters

zwallet can accept the following global parameters to override default configuration and can be used with any command.
--config string config file (default is config.yaml)
--configDir string configuration directory (default is $HOME/.zcn)
--fee float transaction fee for the given transaction (if unset, it will be set to blockchain min fee)
-h, --help help for zwallet
--network string network file to overwrite the network details (if required, default is network.yaml)
--silent Do not print sdk logs in stderr (prints by default)
--wallet string wallet file (default is wallet.json)
--withNonce int nonce that will be used in transaction (default is 0)
The --network and --config flags are used to specify yaml file for network configuration used by zbox, by default files are stored in .zcn directory are used.
Sample Command:
./zwallet <command> --wallet wallet2.json​

Creating a Second Wallet

The wallet by default gets saved at the location~/.zcn/wallet.json. To create a second or multiple wallets wallet you must use the --wallet flag and create a new json file. Here is a command for creating a second wallet with some test tokens. The configuration for second wallet is saved in new_wallet.json file:
./zwallet create-wallet --wallet wallet2.json
wallet saved in /$PATH/.zcn/wallet2.json
The second wallet will also be saved in .zcn directory. To check its contents use:
cat ~/.zcn/wallet2.json
Sample Response:
{"client_id":"0a145e6df5d9c0e8307bdec84a73b01e9ea0dc10a8c09128253935d7a10d6f13","client_key":"272b168ed806d09b2937f90185093d5c68130479f3afeb7c5ec91394d011ac1289adcf093a2c3121de5f0549e6863a8f946758367847bb27fdb93e48d505fa94","keys":[{"public_key":"272b168ed806d09b2937f90185093d5c68130479f3afeb7c5ec91394d011ac1289adcf093a2c3121de5f0549e6863a8f946758367847bb27fdb93e48d505fa94","private_key":"e699ba95136a6cffe8cd4e8e008ef5e76e4d6cadcd8f9399da407585bfaedf10"}],"mnemonics":"mask whip cotton crunch motor range solar path impose race certain pole swim decide cross donkey dove source essay update rebuild lesson chicken income","version":"1.0","date_created":"2021-05-17 20:27:27.110948873 +0000 UTC m=+0.137667608"}

Recovering a wallet

./zwallet recoverwallet command can be used to restore your lost wallet or loading your wallet on a different computer.
Parameters required for recovering your wallet can be viewed using ./zwallet recoverwallet --help command
Here are the Parameters
zwallet recoverwallet [flags]
-h, --help help for recoverwallet
--mnemonic string mnemonic
A mnemonic string is required to recover and recreate your wallet. The mnemonic string is generated when you have first created your wallet and it is stored by default in wallet.json file located in .zcn directory until specified.
It is advised to safely store and copy the mnemonic string at some other location in your computer as it is used for many ZWallet functionaities.
For demonstrating the recover wallet functionality, we will find the mnemonic string for the wallet on UserA computer and recover it on UserB computer.
To find mnemonic in wallet file use cat command with the wallet file name on user A computer:
cat ~/.zcn/wallet.json
{"client_id":"26e5b70fcba3f72a475ef1dbc66e454d3b458b950d62c6ec218cc3425e3b621f","client_key":"9a463e83d67586b661187ee757187d17623205764f2a7584b7aa1383a4159c0f158090b0168ad6e3b7eaf7e5fe107eb4e71d280dc46c60d8b2b21d4eae8e711f","keys":[{"public_key":"9a463e83d67586b661187ee757187d17623205764f2a7584b7aa1383a4159c0f158090b0168ad6e3b7eaf7e5fe107eb4e71d280dc46c60d8b2b21d4eae8e711f","private_key":"4bf7ee2873b0a0c29766a72bc5ccc74f167159266c67556fa0ca87286f7a2218"}],"mnemonics":"penalty sound feed follow come paddle rule brand shift embrace olive expire bundle join churn actress chief venue picnic old tower cover lake zebra","version":"1.0","date_created":"2021-05-11 18:22:52.339539274 +0000 UTC m=+0.075234202"}root@ip-172-31-29-158:~/zboxcli/zwalletcli#
Here mnemonics string is penalty sound feed follow come paddle rule brand shift embrace olive expire bundle join churn actress chief venue picnic old tower cover lake zebra
Now let's recover the wallet by using this mnemonic on UserB computer. The name we will specify for the wallet would be recovered_wallet.json
Sample Command:
./zwallet recoverwallet --wallet recovered_wallet.json --mnemonic "penalty sound feed follow come paddle rule brand shift embrace olive expire bundle join churn actress chief venue picnic old tower cover lake zebra"
No wallet in path /root/.zcn/recovered_wallet.json found. Creating wallet...
ZCN wallet created!!
Creating related read pool for storage smart-contract...
Read pool created successfully
Wallet recovered!!
Verify whether it is the same wallet using:
cat ~/.zcn/recovered_wallet.json
The contents in the json file should be same as User A computer .\

Sending tokens to another wallet

./zwallet send command is used to transfer tokens from one wallet to another. Parameters for send command can be viewed using ./zwallet send --help.
zwallet send [flags]
--desc string Description
--fee float Transaction Fee
-h, --help help for send
--to_client_id string to_client_id
--tokens float Token to send
Here with --desc flag the reason for sending tokens can be specified,--fee flag specifies the cost to send the certain amount of tokens(the fee is specified by the miner and gets deducted from senders wallet), client id for the reciever wallet is required and can be fetched by viewing the contents of their wallet.json file. Lastly number of tokens which has to be send to another wallet has to be specified.
Note: The desc, client id and tokens flag are required flags for send command. The command wont work without them.fee flag is optional.
For demonstration, let's send 0.1 tokens with a fee of 0.1 from our wallet to a specified client ID as a gift.
Before sending lets check our wallet balance using:
./zwallet getbalance
Sample Response:
Balance: 0.6 (0.69 USD)
By default ZWallet checks balance and send tokens from wallet specified in wallet.json file. To send tokens use:
./zwallet send --to_client_id 26e5b70fcba3f72a475ef1dbc66e454d3b458b950d62c6ec218cc3425e3b621f --tokens .2 --desc "gift" --fee 0.1
Send tokens success
To verify whether tokens are sent to the receiver, check the wallet balance. The tokens specified in send command and transaction fee should be deducted from your wallet balance.
Balance: 0.4 (0.45199999999999996 USD)
Note: To use a different wallet as a sender, use --wallet global parameter.
./zwallet send --to_client_id 26e5b70fcba3f72a475ef1dbc66e454d3b458b950d62c6ec218cc3425e3b621f --tokens .1 --desc "gift" --fee 0.1 --wallet another_wallet.json