Managing Accounts
List Your Accounts
This will return the list of all accounts created under the data directory.
ken
From the command line, call the CLI with:
NOTE: This order of returned account list can change if you copy keystore files from other nodes or remove the files. Therefore, make sure you either do not rely on the index or make sure if you copy or remove keystore files you check and update your account indexes in your scripts.
JavaScript Console
When using the console:
Unlock Accounts
If you want to use an account non-interactively, you need to unlock it.
ken
You can unlock accounts and start the EN on the command line with the --unlock "{address},{address}"
option which takes a comma-separated list of accounts (in hex or index) as an argument so you can unlock the accounts programmatically for one session. This is useful if you want to use your account from dApps via RPC. --unlock
will unlock the first account in the list. This is useful when you created your account programmatically, you do not need to know the actual account to unlock it.
Create an account and start a node with the account unlocked:
If you want to start a node with a specific account unlocked, you can use an address or an index which refers to the address position in the account list (and corresponds to the order of creation).
The command line allows you to unlock multiple accounts. In this case, the argument to unlock is a comma-separated list of account addresses or indexes.
If this construction is used non-interactively, your password file will need to contain the respective passwords for the accounts in question, one per line.
JavaScript Console
On the console you can also unlock accounts (one at a time) for a duration (in seconds).
Note that we do NOT recommend using the password argument here, since the console history is logged, so you may compromise your account. You have been warned.
Check Account Balance
ken
n/a
JavaScript Console
To check your account balance:
Print all balances with a JavaScript function:
That can then be executed with:
Since this function will disappear after restarting ken
, it can be helpful to store commonly used functions to be called later.
First, save the checkAllBalances()
function definition to a file on your computer. For example, /Users/username/klayload.js
. Then load the file from the interactive console:
The file will modify your JavaScript environment as if you have typed the commands manually. Feel free to experiment!
Last updated