Documentation Index
Fetch the complete documentation index at: https://hedera-0c6e0218-514-egress-ports.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
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 the Hiero CLI repository:create-account-demo.sh— operator setup, create account, view accounttransfer-hbar-demo.sh— two accounts and an HBAR transfertoken-topic-operations-demo.sh— token and topic operations
examples/scripts/common/ (helpers.sh, setup.sh). See the folder’s README for how to run the demos.
Prerequisites
- Node.js installation: 18.0.0 or higher
- Local mode (default): clone hiero-cli, then in the project root run
npm installandnpm run buildsodist/hiero-cli.jsexists - Global mode (optional): install the CLI with
npm install -g @hiero-ledger/hiero-cliand setHIERO_SCRIPT_CLI_MODE=globalwhen running a script (see below) - Operator credentials:
HEDERA_OPERATOR_ACCOUNT_IDandHEDERA_OPERATOR_KEY. Copyexamples/scripts/.env.sampletoexamples/scripts/.envand fill in your values, or export both variables in your shell
Script structure (recommended pattern)
All example scripts follow the same layout:Step 1: Strict bash mode
-eexit immediately on error-uerror on undefined variables-opipefail fail if any command in a pipe fails
Step 2: Paths, helpers, and setup
Resolve the script directory and repository root, then sourcecommon/helpers.sh and common/setup.sh:
helpers.sh— definesrun_hcli(local vs global CLI),print_step,print_info,print_warn,sleep_loop, andpick_random_namesetup.sh— loads optionalexamples/scripts/.env, runs dependency/build checks in local mode, and validates required operator env vars
Step 3: run_hcli (where automation begins)
From helpers.sh, commands go through run_hcli instead of calling hcli or node dist/hiero-cli.js directly:
- Ensures every invocation uses
--format jsonso scripts parse output reliably - Local: runs the built CLI from
PROJECT_DIR - Global: runs the
hclion yourPATH(afternpm install -g @hiero-ledger/hiero-cli)
HIERO_SCRIPT_CLI_MODE=global when invoking a script if you do not want to build from source. The default is local.
Quickstart: create an account and view it
The canonical example iscreate-account-demo.sh. From the hiero-cli repository root (with HEDERA_OPERATOR_* set or .env configured):
1.0 HBAR, waits briefly for mirror indexing, then runs account view.
network use in the example scripts
When HIERO_SCRIPT_CLI_MODE=global, the demos call network use --network testnet. When using the default local build, they call network use --global testnet. Keep the same branch as the script you are running. If a command fails or the help text differs, use hcli network use --help for the CLI you actually execute.create-account-demo.sh (paths, run_hcli, operator setup, create + view). For a maintained, executable copy, use that file in the repo; this block is for reading the pattern:
examples/scripts/README.md in the Hiero CLI repository.