hashgraph / hedera-cli

Hedera command line tools for developers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CircleCI Codacy Badge Codacy Badge Maintainability GitHub release (latest by date) GitHub

Hedera CLI

This is a simple quick start tool to understand the apis via gRPC that Hedera platform provides.

To get started, you must either have a mainnet or a testnet account.

You can register at portal.hedera.com to get an account, or get another user who already has an account to create one for you.

A Hedera account is represented in a numeric format, delimited by 2 dots. For example 0.0.1234. The first number in this example "0" represents the shard number. The second number "0" represents the realm number and the last number "1234" is the account number.

Overview

Hedera currently has 3 services.

  1. Crypto service
  2. File service
  3. Smart contract service

and an upcoming 4th service - Hedera consensus service.

To read what Hedera has to offer, you can check out

  1. docs.hedera.com
  2. hedera.com
  3. Hedera's whitepaper

Description

Prerequisites

Hedera CLI works with Java versions 10/11/12.

Quick Start

There are 2 ways to start Hedera CLI.

The first, download hedera cli via brew tap or curl.

# macOS
brew tap hashgraph/tap
brew install hedera-cli

# unix / linux
curl -s https://raw.githubusercontent.com/hashgraph/hedera-cli/master/install.sh | sudo bash

To run the hedera shell,

hedera

Once that is running, you should see this


Commands

Setup operator account

There is the concept of an operator account where the operator can pay for the transaction costs, ie network and node fees.

Cli will prompt setup on first run to save default operator key into ~/.hedera. Setting up an operator can be done with either passphrase or private key

  1. 24 recovery words, where words are separated by spaces.
  2. Private key either in hexadecimal or ASN1 encoded format.

AccountGetInfo is called during setup to confirm the account exists on Hedera. This will cost some tinybars. The default operator can be changed anytime by using account use 0.0.xxxx.

# Sets the default operator
setup

Switch to a specific network

# To see the list of available networks
network ls

# To change network
network use mainnet
network use testnet

List Accounts

# Lists all accounts associated with current network
account ls

Version (v0.1.6)

# Checks current version
version

Switch Accounts

# Switch to use any account that has been recovered and exists in `account ls`
account use 0.0.xxxx

Default Accounts (v0.1.3)

The account must have been recovered and exists in account ls

# Sets the account as default operator. 
account default 0.0.xxxx

Recover Accounts

Recovering an Hedera account using either

  1. 24 recovery words, where words are separated by spaces.
  2. Private key either in hexadecimal or ASN1 encoded format.
# Recovering an Hedera account
account recovery 0.0.xxxx

Create Account

Account creation can be done in multiple ways.

Simple Key

  1. Creating an account using new recovery words and keypair.
  2. Creating an account using operator's keypair.
  3. Creating an account using any public key (not yet supported).

MultiSig account creation (not yet supported)

# Creates a new Hedera account using NEW recovery words and keypair. This is default.
account create -b 100000000

# Creates a new Hedera account using Operator's public key 
account create -b 100000000 -k

Delete Account

Cli will prompt for key of account(-o) that is set for deletion. Only the account for deletion can sign the transaction.

# Deletes an account from Hedera, and transfers the remaining funds from the deleted account to the new account
account delete -o 0.0.1001 -n 0.0.1002
account delete --oldAccount 0.0.1001 --newAccount 0.0.1002

Account Balance

Account balance calls are free.

# Gets the balance of an account
account balance 0.0.xxxx

Account Get Info

Gets the information of an account, such as the public keys, and stateproofs (upcoming)

# Gets the information of an account
account info 0.0.xxxx

Account Update (v0.1.3)

Cli will prompt for original key as well as the new key that said account will be updated with.

# Updated the keypair of account
account update 0.0.xxxx 

Help

# shows all the available commands
help

Cryptotransfer (v0.1.5)

Cryptotransfer in tinybars(-tb) or hbars(-hb). Tinybars are integers while hbars can be down to 8 decimals. Recipients(-r) are separated by commas

Valid commands
## hedera [testnet][0.0.112533] :>

## Sender is not operator
transfer -s 0.0.119312 -r 0.0.116681,0.0.121290 -tb -500,300,200
transfer -s 0.0.119312 -r 0.0.116681,0.0.121290 -hb -5,3,2
transfer -s 0.0.119312 -r 0.0.116681,0.0.121290 -hb -0.005,0.003,0.002

## Sender is operator
transfer -s 0.0.112533 -r 0.0.116681,0.0.121290 -hb -0.005,0.003,0.002
transfer -s 0.0.112533 -r 0.0.116681,0.0.121290 -hb -5,3,2
transfer -s 0.0.112533 -r 0.0.116681,0.0.121290 -tb 3000000,2000000
transfer -s 0.0.112533 -r 0.0.116681,0.0.121290 -tb -5000000,3000000,2000000
transfer -s 0.0.112533 -r 0.0.116681,0.0.121290 -tb 3000000,2000000

transfer -r 0.0.116681,0.0.121290 -tb 3000000,2000000
transfer -r 0.0.116681,0.0.121290 -tb -5000000,3000000,2000000
transfer -r 0.0.116681,0.0.121290 -hb -0.5,0.3,0.2
transfer -r 0.0.116681,0.0.121290 -hb 0.3,0.2

About

Hedera command line tools for developers

License:Apache License 2.0


Languages

Language:TypeScript 99.2%Language:Dockerfile 0.5%Language:JavaScript 0.3%Language:Shell 0.0%