my-hedera
v1.0.4
Published
My Hedera Command Line Tool
Downloads
2
Readme
Introduction
This command line tool is an experimentation to see how interesting and easy we could use command line to interact with the Hedera platform. As of today, this tools allows you only to get a balance or to send hBars to someone else.
Requirements
You'll need obviously npm
to install it. You can refer to the NodeJS documentation to know how to install it:
https://nodejs.org/en/download/package-manager/
When that's done, just type:
npm i -g my-hedera
It will install the command line my-hedera
on your computer. When you are done, you should be able to run:
$ my-hedera -h
__ __ _ _ _ _ _
| \/ |_ _ | | | | ___ __| | ___ _ __ __ _| | |
| |\/| | | | | | |_| |/ _ \/ _` |/ _ \ '__/ _` | | |
| | | | |_| | | _ | __/ (_| | __/ | | (_| |_|_|
|_| |_|\__, | |_| |_|\___|\__,_|\___|_| \__,_(_|_)
|___/
Welcome to Hedera!
Java Version: 11.02
usage: my-hedera
-a,--account <arg> Your account number to use the Hedera network (you
can as well use the environment variable
MYHEDERA_ACCOUNTNUM)
-b,--balance <arg> Account number you want to get the balance
-h,--help print this message
-k,--key <arg> Your private key to use the Hedera network (you can
as well use the environment variable
MYHEDERA_OPERATORKEY)
-n,--node <arg> List of nodes that you would like to connect. The
syntax must be this one: <NODE ID>:<IP OR SERVER
NAME>:<PORT> (example for the node 0.0.3 on the main
net: 3:35.237.200.180:50211
-s,--send <arg> Account number you want to send tinybars
-t,--tiny <arg> Amount of tinybars to send
Be aware that this package is just a bundle of a JAR file that I created. Why Java? Because the Java SDK is today the only maintained by Hedera. The consequence is that you'll need Java 11 running on your computer. If not, you'll get a message like this:
$ my-hedera -h
__ __ _ _ _ _ _
| \/ |_ _ | | | | ___ __| | ___ _ __ __ _| | |
| |\/| | | | | | |_| |/ _ \/ _` |/ _ \ '__/ _` | | |
| | | | |_| | | _ | __/ (_| | __/ | | (_| |_|_|
|_| |_|\__, | |_| |_|\___|\__,_|\___|_| \__,_(_|_)
|___/
Welcome to Hedera!
Java Version: 1.80121
Unfortunately, you need Java 11...
You'll find an easy documentation to follow on how to install Java here:
https://java.com/en/download/help/download_options.xml
Usage
Let's start by checking my balance. My account ID is 0.0.2211
, so if you type this command, it will ask to authenticate against the network:
$ my-hedera -b 2211
__ __ _ _ _ _ _
| \/ |_ _ | | | | ___ __| | ___ _ __ __ _| | |
| |\/| | | | | | |_| |/ _ \/ _` |/ _ \ '__/ _` | | |
| | | | |_| | | _ | __/ (_| | __/ | | (_| |_|_|
|_| |_|\__, | |_| |_|\___|\__,_|\___|_| \__,_(_|_)
|___/
Welcome to Hedera!
Java Version: 11.02
The option -a is required. Please specify your account number or set the environment variable MYHEDERA_ACCOUNTNUM.
You can pass the authentication in the command line tool:
$ my-hedera -b 2211 -a <YOUR ACCOUNT NUMBER ONLY> -key <YOUR PRIVATE KEY>
Or just using environment variables:
export MYHEDERA_ACCOUNTNUM=2211
export MYHEDERA_OPERATORKEY=xxx
I prefer this option, like that, I'm not required to provide it for each call. And you should get:
$ my-hedera -b 2211
__ __ _ _ _ _ _
| \/ |_ _ | | | | ___ __| | ___ _ __ __ _| | |
| |\/| | | | | | |_| |/ _ \/ _` |/ _ \ '__/ _` | | |
| | | | |_| | | _ | __/ (_| | __/ | | (_| |_|_|
|_| |_|\__, | |_| |_|\___|\__,_|\___|_| \__,_(_|_)
|___/
Welcome to Hedera!
Java Version: 11.02
Configuring the Hedera client
Account ID: 0.0.2211
Operator Key: ....2371
Nodes
Node ID: 0.0. 3 Server: 35.237.200.180:50211
Node ID: 0.0. 4 Server: 35.186.191.247:50211
Node ID: 0.0. 5 Server: 35.192.2.25:50211
Collecting the balance
Account ID: 0.0.2211
The balance of the account 0.0.2211 is :
127 802 673 575 tinyBar(s)
OR 1 278.03 hBar(s)
Of course, if you want to donate some hBars to encourage myself to pursue it, feel free ;)
As you can see, by default, the tool connect to the mainnet. If you want to connect to the testnet, just provide the valid sever details like that:
$ my-hedera -b 1237 -n 3:0.testnet.hedera.com:50211 -n 4:1.testnet.hedera.com:50211 -n 5:2.testnet.hedera.com:50211 -n 6:3.testnet.hedera.com:50211
__ __ _ _ _ _ _
| \/ |_ _ | | | | ___ __| | ___ _ __ __ _| | |
| |\/| | | | | | |_| |/ _ \/ _` |/ _ \ '__/ _` | | |
| | | | |_| | | _ | __/ (_| | __/ | | (_| |_|_|
|_| |_|\__, | |_| |_|\___|\__,_|\___|_| \__,_(_|_)
|___/
Welcome to Hedera!
Java Version: 11.02
Configuring the Hedera client
Account ID: 0.0.1274
Operator Key: ....99fc
Nodes
Node ID: 0.0. 3 Server: 0.testnet.hedera.com:50211
Node ID: 0.0. 4 Server: 1.testnet.hedera.com:50211
Node ID: 0.0. 5 Server: 2.testnet.hedera.com:50211
Node ID: 0.0. 6 Server: 3.testnet.hedera.com:50211
Collecting the balance
Account ID: 0.0.1237
The balance of the account 0.0.1237 is :
100 400 901 330 tinyBar(s)
OR 1 004.01 hBar(s)
Note that you don't need to provide all nodes, just one will do if it's running...
Finally, let's see how to send tiny bars. You just need to use -s <RECIPIENT ACCOUNT NUM>
and -t <NUMBER OF TINY BARS TO SEND>
:
$ my-hedera -s 1238 -t 1 -n 3:0.testnet.hedera.com:50211 -n 4:1.testnet.hedera.com:50211 -n 5:2.testnet.hedera.com:50211 -n 6:3.testnet.hedera.com:50211
__ __ _ _ _ _ _
| \/ |_ _ | | | | ___ __| | ___ _ __ __ _| | |
| |\/| | | | | | |_| |/ _ \/ _` |/ _ \ '__/ _` | | |
| | | | |_| | | _ | __/ (_| | __/ | | (_| |_|_|
|_| |_|\__, | |_| |_|\___|\__,_|\___|_| \__,_(_|_)
|___/
Welcome to Hedera!
Java Version: 11.02
Configuring the Hedera client
Account ID: 0.0.1237
Operator Key: ....ba12
Nodes
Node ID: 0.0. 3 Server: 0.testnet.hedera.com:50211
Node ID: 0.0. 4 Server: 1.testnet.hedera.com:50211
Node ID: 0.0. 5 Server: 2.testnet.hedera.com:50211
Node ID: 0.0. 6 Server: 3.testnet.hedera.com:50211
Sending hBars
Recipient Account ID: 0.0.1238
Amount of tinyBars: 1
Done!