Quick cleos guide for UX Network

From Democratic Money wiki
Revision as of 18:24, 19 September 2020 by Fcecin (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

cleos is a command-line wallet for EOSIO blockchains. It is an alternative to using a graphical or web wallet. It's used mostly by developers, but whatever can be done in a graphical or web wallet can be done by cleos.

Installing cleos

cleos comes as part of the EOSIO installer, which will install a lot of other stuff as well (such as nodeos).

Download and run the latest installer of EOSIO for your platform: https://github.com/EOSIO/eos/releases

cleos wallets

Just use the default wallet. The commands below interact with the default wallet.

cleos wallet create

This creates the default wallet. Remember to write down the wallet password that is automatically generated, otherwise you won't be able to unlock it later.

cleos wallet open

Opens the default wallet.

cleos wallet unlock

Unlocks the default wallet, exposing the private keys for use. You must enter the wallet password that was shown to you when you used the "cleos wallet create" command.

cleos wallet list

Lists the available wallets. It should show the "default" wallet.

cleos wallet list keys

Lists all of the public keys associated with the private keys that are stored inside the wallet.

cleos create key --to-console

This creates a public and private key pair and prints it to the screen. The private keys generated by this command are not automatically stored inside the wallet, they are really just printed to the screen. If you want to use a key pair generated by this command, you need to use the import command (see below).

cleos wallet import

The import command can be used to import private keys into the wallet. You can put the active private key for your UTX accounts here, if you want cleos to act as one of your wallets.

cleos wallet lock

This makes sure the wallet is locked, protecting the private keys from any further use.

Using cleos with an API node

cleos --url https://api.uxnetwork.io

All cleos commands that don't interact with the wallet require the --url option after "cleos" so that cleos knows which blockchain it is supposed to interact with. We will omit the "--url https://api.uxnetwork.io" prefix from the following command examples (so you need to remember to add it back).

cleos system newaccount genesis111cd dailycoinubi EOS7rbndd1su1rVZKZsEnBPTYmr4nho2rQt7tgv1sNyrBjgBtzkxv EOS5SwjJ6ZqENzwXb1yUYDaQjHrLj9WwuSKeS5qRhkq8CmaX8gtx8 --stake-net "1000.0000 UTX" --stake-cpu "1000.0000 UTX" --buy-ram-kbytes 550 -p genesis111cd

The above command shows how an account called 'genesis111cd' created the 'dailycoinubi' account, and then temporarily staked 1000 UTX for network and 1000 UTX for CPU for the new account. It also spent 550 of its own UTXRAM to buy 550 KiB of RAM to the new account. Finally, it assigned the above owner and active public keys to the new account (the owner key is the first one).

The "-p" option is used with any cleos command that requires the transaction to be signed by some account. After "-p", you put the name of the account that is signing the transaction. By default, the "active" key of that account will be used to sign it. You can sign the transaction with an account's owner key by using -p myacountname@owner instead (though you shouldn't be putting your private owner key in a PC that's connected to the internet, not even inside of a password-protected wallet like cleos; ideally, your owner key never leaves your paper backups or hardware wallets).

In case this isn't obvious, when using "-p" you need the private (active) key of the account you're using to sign the transaction to be already imported into your default cleos wallet. Also, the wallet must be unlocked (it locks automatically after a period of inactivity, so you may have to unlock it again).

cleos system buyram genesis111cd dailycoinwbi "50 UTXRAM" -p genesis111cd

The above command would cause the "genesis111cd" account to buy 50 UTXRAM worth of RAM to the "dailycoinubi" account.

cleos system buyram genesis111cd genesis111cd "10 UTXRAM" -p genesis111cd

The above command would cause "genesis111cd" to buy 10 UTXRAM worth of RAM to itself.

cleos get table eosio.token genesis111cd accounts

The above command shows the UTX and UTXRAM token balances for account "genesis111cd".

cleos get table dailycoinwbi genesis111cd accounts

The above command shows the XDL (Dailycoin) token balance for the account genesis111cd.

cleos get account genesis111cd

This gets basic information about account "genesis111cd".

cleos system --help

Show the available system commands. Two useful system commands are "delegatebw" and "undelegatebw", which stake and unstake UTX tokens.

cleos push action eosio.token transfer '{"from":"genesis111cd", "to":"someaccount1", "quantity":"12.5000 UTX", "memo":"testing transfer with cleos"}' -p genesis111cd

The "push action" cleos command allows you to call any action on any contract. The above example calls the "transfer" action on the token contract that is deployed on the "eosio.token" account on UX. That action, of a standard EOSIO token contract, is used to transfer tokens from one token owner to another. It takes four parameters, which are named "from", "to", "quantity" and "memo", which you should be familiar with if you have interacted with any graphical or web wallet before. Note that the full precision of the token needs to be expressed in the "quantity" field, otherwise the command won't work (most EOSIO token symbols have a precision of 4 decimal places, so that's always a good guess).

cleos push action eosio.token transfer '["genesis111cd", "someaccount1", "12.5000 UTX", "testing transfer with cleos"]' -p genesis111cd

This is the exact same as the previous command, but with less typing. If you specify the parameters in the correct order, you can omit the name of the parameters, using this square brackets notation instead of the curly brackets one.