Skip to main content
Learn how to create a new Hedera account on testnet using the JavaScript, Java, Go, SDK, or Python. A Hedera account is your identity on‑chain. It holds your HBAR (the network’s currency) and lets you sign transactions.

Prerequisites

  • A Hedera testnet operator account ID and ECDSA DER-encoded private key (from the Quickstart).
  • A small amount of testnet HBAR (ℏ) to pay the $0.05 account‑creation fee.
NoteYou can always check the ”Code Check” section at the bottom of each page to view the entire code if you run into issues. You can also post your issue to the respective SDK channel in our Discord community here.

Install the SDK

Open your terminal and create a directory hedera-examples directory. Then change into the newly created directory:
Initialize a node.js project in this new directory:
Ensure you have Node.js v18 or later installed on your machine. Then, install the JavaScript SDK.
Update your package.json file to enable ES6 modules and configure the project:
Create a createAccountDemo.js file and add the following imports:

Environment Variables

Set your testnet operator credentials as environment variables. Your OPERATOR_ID is your testnet account ID. Your OPERATOR_KEY is your testnet account’s corresponding ECDSA private key.

Step 1: Initialize Hedera Client

Load your operator credentials from environment variables and initialize your Hedera testnet client. This client will connect to the Hedera test network and use your operator account to sign transactions and pay transaction fees.

Step 2: Generate a New Key Pair

Generate a new ECDSA private/public key pair for the account you’ll create.

Why keys?

On the Hedera network, a private key allows you to sign transactions, ensuring only you control your assets, while a public key, shared on-chain, verifies your identity. This key pair is essential for account security.
‼️ Security reminder: Keep your private keys secure - anyone with access can control your account and funds.

Step 3: Create Your First Account on Hedera

Build an AccountCreateTransaction with the new public key and initial balance, then execute it. Specify the public key , an optional initial HBAR balance, and once you execute it, the network creates the account and returns the new AccountId in the receipt.

Step 4: Query the Account Balance Using Mirror Node API

Use the Mirror Node REST API to check your new account’s HBAR balance. Mirror nodes provide free access to network data without transaction fees. API endpoint:
Replace the placeholder:
  • {accountId} - Your new account ID from the creation transaction
Why this endpoint? This endpoint queries account balances directly by account ID. It returns detailed information including HBAR balance in tinybars, making it ideal for verifying the new account was funded with the expected initial balance.
Example URLs:
Complete Implementation:

✅ Code check

Before running your project, verify your code matches the complete example:

Run Your Project

Ensure your environment variables are set:

Expected sample output:

‼️ Troubleshooting

Error messageLikely causeFix
INSUFFICIENT_PAYER_BALANCEOperator account lacks enough ℏ for the fee.Top‑up your testnet account with the HBAR faucet.
INVALID_SIGNATUREOperator key doesn’t match operator accountVerify OPERATOR_KEY matches your OPERATOR_ID
INVALID_ACCOUNT_IDMalformed account ID in environment variablesVerify OPERATOR_ID format is 0.0.1234
INVALID_PRIVATE_KEYMalformed private key in environment variablesVerify OPERATOR_KEY is a valid DER-encoded private key string
KEY_REQUIREDMissing key in AccountCreateTransactionEnsure you call .setECDSAKeyWithAlias(newPublicKey)
OPERATOR_ID and OPERATOR_KEY must be setEnvironment variables not accessibleCheck environment variables are set and accessible to your application
Cannot read properties of undefinedMissing imports or undefined variablesVerify all imports are included and variables are defined

What just happened?

  1. The SDK built an AccountCreateTransaction and signed it with your operator key.
  2. A consensus node validated the signature and charged the account creation fee.
  3. After network consensus, a unique account ID and EVM address were assigned and returned in the receipt.
  4. The account was funded with 20 HBAR from your operator account.
  5. The Mirror Node API confirmed your new account exists with the expected balance.

Next steps


🎉 Great work! You now control a brand new Hedera account secured by your fresh key pair. Keep the private key safe and never commit it to source control.

Additional resources

Accounts | Hedera