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.
A Hedera testnet operator account ID and ECDSADER-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 communityhere.
Create a createAccountDemo.js file and add the following imports:
Copy
Ask AI
import { Client, PrivateKey, AccountCreateTransaction, Hbar,} from "@hashgraph/sdk";
Add the Java SDK dependency to your Maven project’s pom.xml and create your source file:Create a new Maven project and name it HederaExamples. Add the following dependencies to your pom.xml file:
Or for Gradle projects using the Groovy DSL, add these dependencies to your build.gradle file and install the dependencies using ./gradlew build
Copy
Ask AI
plugins { id 'java' id 'application'}repositories { mavenCentral()}dependencies { implementation 'com.hedera.hashgraph:sdk:2.60.0' implementation 'com.google.code.gson:gson:2.10.1' implementation 'io.grpc:grpc-netty-shaded:1.61.0'}application { mainClass = 'CreateAccountDemo' // or 'com.example.CreateAccountDemo' if it's in a package}
Create a CreateAccountDemo.java class in src/main/java/ with the following imports:
Copy
Ask AI
import com.hedera.hashgraph.sdk.*;import java.net.http.HttpClient;import java.net.http.HttpRequest;import java.net.http.HttpResponse;import java.net.URI;import com.google.gson.Gson;import com.google.gson.JsonObject;import com.google.gson.JsonArray;public class CreateAccountDemo { public static void main(String[] args) throws Exception { // Your account creation code will go here }}
Create a new file create_account_demo.go and import the following packages to your file:
In your project’s root directory, initialize modules and pull in the Go SDK:
Copy
Ask AI
go mod init create_account_demogo get github.com/hiero-ledger/hiero-sdk-go/v2@latestgo mod tidy
Before you start: Ensure you have Python 3.10+ installed on your machine. Run this command to verify.
Copy
Ask AI
python --version
If the python --version command is not found or shows a version lower than 3.10, install or upgrade Python from Python Install.Note: On some systems, you may need to use python3 instead of python for initial setup commands. If python --version doesn’t work, try python3 --version and use python3 for the virtual environment creation. After activating the virtual environment, always use python for all commands.Open your terminal and create a working directory for your Hedera project. Then navigate into the new directory:
Copy
Ask AI
mkdir hedera-examples && cd hedera-examples
Verify Python and pip: Ensure you have Python 3.10+ and pip installed on your machine. Run these commands to check:
Copy
Ask AI
python --version
Copy
Ask AI
python -m pip --version
Create a virtual environment to isolate your project dependencies (Python best practice):
Copy
Ask AI
python -m venv .venv
Activate the virtual environment to use the isolated Python installation:
Mac/Linux
Windows
Copy
Ask AI
source .venv/bin/activate
Copy
Ask AI
.venv\Scripts\activate
Upgrade pip to ensure you have the latest package installer (recommended):
Create a file named CreateAccountDemo.py and add the following imports:
Copy
Ask AI
import osimport timeimport requestsfrom hiero_sdk_python import ( Client, AccountId, PrivateKey, AccountCreateTransaction, Hbar,)# Used to print the EVM address for the new ECDSA public keyfrom hiero_sdk_python.utils.crypto_utils import keccak256
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.
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.
Copy
Ask AI
// Load your operator credentialsconst operatorId = process.env.OPERATOR_ID;const operatorKey = process.env.OPERATOR_KEY;// Initialize your testnet client and set operatorconst client = Client.forTestnet().setOperator(operatorId, operatorKey);
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.
Copy
Ask AI
// generates a new ECDSA key pair in memoryconst newPrivateKey = PrivateKey.generateECDSA();const newPublicKey = newPrivateKey.publicKey;
‼️ Security reminder: Keep your private keys secure - anyone with access
can control your account and funds.
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.
Copy
Ask AI
// Build & execute the account creation transactionconst transaction = new AccountCreateTransaction() .setECDSAKeyWithAlias(newPublicKey) // set the account key .setInitialBalance(new Hbar(20)); // fund with 20 HBARconst txResponse = await transaction.execute(client);const receipt = await txResponse.getReceipt(client);const newAccountId = receipt.accountId;console.log(`\nHedera Account created: ${newAccountId}`);console.log(`EVM Address: 0x${newPublicKey.toEvmAddress()}`);
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:
Copy
Ask AI
/api/v1/balances?account.id={accountId}
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.
🎉 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.