Run repeatable, non-interactive Hiero CLI scripts for Hedera workflows like creating accounts, transferring HBAR, and submitting topic messages, safe for CI.
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:
Local mode (default): clone hiero-cli, then in the project root run npm install and npm run build so dist/hiero-cli.js exists
Global mode (optional): install the CLI with npm install -g @hiero-ledger/hiero-cli and set HIERO_SCRIPT_CLI_MODE=global when running a script (see below)
Operator credentials: HEDERA_OPERATOR_ACCOUNT_ID and HEDERA_OPERATOR_KEY. Copy examples/scripts/.env.sample to examples/scripts/.env and fill in your values, or export both variables in your shell
These are required for scripts that submit transactions to Hedera (e.g., create account, transfer, token operations).
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.
Below is the same sequence as in 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:
#!/usr/bin/env bashset -euo pipefailSCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"PROJECT_DIR="$(cd "${SCRIPT_DIR}/../.." && pwd)"source "$SCRIPT_DIR/common/helpers.sh"source "$SCRIPT_DIR/common/setup.sh"print_step "Selecting Hedera testnet as the active network"if [[ "${HIERO_SCRIPT_CLI_MODE}" == "global" ]]; then run_hcli network use --network testnetelse run_hcli network use --global testnetfiprint_step "Configuring CLI operator for testnet"run_hcli network set-operator \ --operator "${HEDERA_OPERATOR_ACCOUNT_ID}:${HEDERA_OPERATOR_KEY}" \ --network testnetACCOUNT_NAME="$(pick_random_name)"print_step "Creating demo account: ${ACCOUNT_NAME} (1 HBAR)"run_hcli account create --name "${ACCOUNT_NAME}" --balance 1.0print_info "Waiting for mirror node (sleep_loop 5)..."sleep_loop 5print_step "Viewing account ${ACCOUNT_NAME}"run_hcli account view --account "${ACCOUNT_NAME}"print_step "Done."
Explore the other demos and examples/scripts/README.md in the Hiero CLI repository.