1. HMY CLI Download
The Harmony CLI tool is used to interact with the Harmony blockchain.
Make sure NOT to run the Node Setup with theroot user. We recommend creating a new user called harmony for the Node Setup and giving it root level access.
Throughout this guide, we will use the following syntax:
  • ./hmy: This is the CLI program
  • ./hmy.sh -- : This is the command to use the CLI with a shell wrapper (for macOS)
  • <argument>: This is a required argument
  • [argument]: This is an optional argument
  • / : This is a line break, used to break up a line while writing a command

Download Harmony CLI tool

1. For Linux

1
curl -LO https://harmony.one/hmycli && mv hmycli hmy && chmod +x hmy
Copied!

2. For MacOS

1
curl -O https://raw.githubusercontent.com/harmony-one/go-sdk/master/scripts/hmy.sh
2
chmod u+x hmy.sh
3
./hmy.sh -d
Copied!
Now you can use hmy.sh as a wrapper over hmy and you should assume that all references to hmy in these documents refer to hmy.sh. For example, the command ./hmy becomes ./hmy.sh -- .
Note that since hmy is not statically linked, you cannot arbitrarily move hmy.sh to anywhere on your filesystem like you could with a single binary.
On Linux, calling the cookbook would look like this:
1
./hmy --node="https://api.s0.t.hmny.io" cookbook
Copied!
And on MacOS would look like:
1
./hmy.sh -- --node="https://api.s0.t.hmny.io" cookbook
Copied!

Output

1
#Cookbook of Usage
2
​
3
#Note:
4
​
5
#1) Every subcommand recognizes a '--help' flag
6
#2) If a passphrase is used by a subcommand, one can enter their own passphrase interactively
7
# with the --passphrase option. Alternatively, one can pass their own passphrase via a file
8
# using the --passphrase-file option. If no passphrase option is selected, the default
9
# passphrase of '' is used.
10
#3) These examples use Shard 0 of Open Staking Network as argument for --node
11
​
12
#Examples:
13
​
14
#1. Check account balance on given chain
15
./hmy --node="https://api.s0.t.hmny.io" balances <SOME_ONE_ADDRESS>
16
​
17
#2. Check sent transaction
18
./hmy --node="https://api.s0.t.hmny.io" blockchain transaction-by-hash <SOME_TX_HASH>
19
​
20
#3. List local account keys
21
./hmy keys list
22
​
23
#4. Sending a transaction (waits 40 seconds for transaction confirmation)
24
./hmy --node="https://api.s0.t.hmny.io" transfer \
25
--from <SOME_ONE_ADDRESS> --to <SOME_ONE_ADDRESS> \
26
--from-shard 0 --to-shard 1 --amount 200 --passphrase
27
​
28
#5. Sending a batch of transactions as dictated from a file (the `--dry-run` options still apply)
29
./hmy --node="https://api.s0.t.hmny.io" transfer --file <PATH_TO_JSON_FILE>
30
#Check README for details on json file format.
31
​
32
#6. Check a completed transaction receipt
33
./hmy --node="https://api.s0.t.hmny.io" blockchain transaction-receipt <SOME_TX_HASH>
34
​
35
#7. Import an account using the mnemonic. Prompts the user to give the mnemonic.
36
./hmy keys recover-from-mnemonic <ACCOUNT_NAME>
37
​
38
#8. Import an existing keystore file
39
./hmy keys import-ks <PATH_TO_KEYSTORE_JSON>
40
​
41
#9. Import a keystore file using a secp256k1 private key
42
./hmy keys import-private-key <secp256k1_PRIVATE_KEY>
43
​
44
#10. Export a keystore file's secp256k1 private key
45
./hmy keys export-private-key <ACCOUNT_ADDRESS> --passphrase
46
​
47
#11. Generate a BLS key then encrypt and save the private key to the specified location.
48
./hmy keys generate-bls-key --bls-file-path <PATH_FOR_BLS_KEY_FILE>
49
​
50
#12. Create a new validator with a list of BLS keys
51
./hmy --node="https://api.s0.t.hmny.io" staking create-validator --amount 10 --validator-addr <SOME_ONE_ADDRESS> \
52
--bls-pubkeys <BLS_KEY_1>,<BLS_KEY_2>,<BLS_KEY_3> \
53
--identity foo --details bar --name baz --max-change-rate 0.1 --max-rate 0.1 --max-total-delegation 10 \
54
--min-self-delegation 10 --rate 0.1 --security-contact Leo --website harmony.one --passphrase
55
​
56
#13. Edit an existing validator
57
./hmy --node="https://api.s0.t.hmny.io" staking edit-validator \
58
--validator-addr <SOME_ONE_ADDRESS> --identity foo --details bar \
59
--name baz --security-contact EK --website harmony.one \
60
--min-self-delegation 0 --max-total-delegation 10 --rate 0.1\
61
--add-bls-key <SOME_BLS_KEY> --remove-bls-key <OTHER_BLS_KEY> --passphrase
62
​
63
#14. Delegate an amount to a validator
64
./hmy --node="https://api.s0.t.hmny.io" staking delegate \
65
--delegator-addr <SOME_ONE_ADDRESS> --validator-addr <VALIDATOR_ONE_ADDRESS> \
66
--amount 10 --passphrase
67
​
68
#15. Undelegate to a validator
69
./hmy --node="https://api.s0.t.hmny.io" staking undelegate \
70
--delegator-addr <SOME_ONE_ADDRESS> --validator-addr <VALIDATOR_ONE_ADDRESS> \
71
--amount 10 --passphrase
72
​
73
#16. Collect block rewards as a delegator
74
./hmy --node="https://api.s0.t.hmny.io" staking collect-rewards \
75
--delegator-addr <SOME_ONE_ADDRESS> --passphrase
76
​
77
#17. Check elected validators
78
./hmy --node="https://api.s0.t.hmny.io" blockchain validator elected
79
​
80
#18. Get current staking utility metrics
81
./hmy --node="https://api.s0.t.hmny.io" blockchain utility-metrics
82
​
83
#19. Check in-memory record of failed staking transactions
84
./hmy --node="https://api.s0.t.hmny.io" failures staking
85
​
86
#20. Check which shard your BLS public key would be assigned to as a validator
87
./hmy --node="https://api.s0.t.hmny.io" utility shard-for-bls 2d61379e44a772e5757e27ee2b3874254f56073e6bd226eb8b160371cc3c18b8c4977bd3dcb71fd57dc62bf0e143fd08
Copied!

Troubleshooting

Frequently encountered errors:
1
./hmy cookbook
2
​
3
-bash: ./hmy: cannot execute binary file: Exec format error
4
​#Make sure you downloaded the right version for your OS.
Copied!
Last modified 4mo ago