Skip to main content

Scripting with Hiero CLI

Hiero CLI scripts let you run repeatable, end-to-end workflows for Hedera: creating accounts, transferring HBAR, creating tokens, submitting topic messages, and more. These scripts are designed to be non-interactive (safe for CI). Example scripts live in:

Prerequisites

  • Node.js 18+
  • Build the CLI or have a globally installed version of the CLI
  • Provide your Hedera operator credentials. Export these environment variables:
These are required for scripts that submit transactions to Hedera (e.g., create account, transfer, token operations).
All example scripts follow the same layout:

Step 1: Strict bash mode

  • -e exit immediately on error
  • -u error on undefined variables
  • -o pipefail fail if any command in a pipe fails

Step 2: Load helpers & Setup

Scripts load shared utilities from examples/scripts/common/. Typical helpers include:
  • structured log output (print_step, print_info, print_error)
  • random alias generator (pick_random_name)
  • sleep utilities (sleep_loop) to wait for mirror-node consistency

Step 3: hcli() wrapper (where automation begins)

From this point, scripts start executing real CLI commands.
Why this wrapper matters:
  • ensures commands run from the project root
  • uses the built CLI entrypoint
  • forces --format json so scripts don’t depend on human formatting
  • prevents interactive prompts (better for CI / automation)

Quickstart script: create an account and view it

This is the smallest “real” end-to-end example:
  • configure network + operator
  • create one account with 1 HBAR
  • view account details
First, create a file called create-account-quickstart.sh with the below script contents:
Next, run it from the project root:
Start building your own scripts or explore other examples in the Hiero CLI repository.