Learn how to create a new Hedera account on testnet using the JavaScript, Java, or Go SDK. 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 DER-encoded private key (from the Quickstart)
A small amount of testnet HBAR (ℏ) to pay the $0.05 account‑creation fee.
Note
You 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:
mkdirhedera-examples&&cdhedera-examples
Initialize a node.js project in this new directory:
npminit-y
Ensure you have Node.jsv18 or later installed on your machine. Then, install the JavaScript SDK.
npminstall--save@hashgraph/sdk
Update your package.json file to enable ES6 modules and configure the project:
Load your operator credentials from environment variables and initialize your Hedera testnet client. This client will connect to the network and use your operator account to sign transactions and pay fees.
// Load your operator credentials
const operatorId = process.env.OPERATOR_ID;
const operatorKey = process.env.OPERATOR_KEY;
// Initialize your testnet client and set operator
const client = Client.forTestnet()
.setOperator(operatorId, operatorKey);
// Load your operator credentials
AccountId operatorId = AccountId.fromString(System.getenv("OPERATOR_ID"));
PrivateKey operatorKey = PrivateKey.fromString(System.getenv("OPERATOR_KEY"));
// Initialize your testnet client and set operator
Client client = Client.forTestnet().setOperator(operatorId, operatorKey);
// Load your operator credentials
operatorId, _ := hedera.AccountIDFromString(os.Getenv("OPERATOR_ID"))
operatorKey, _ := hedera.PrivateKeyFromString(os.Getenv("OPERATOR_KEY"))
// Initialize the client for testnet
client := hedera.ClientForTestnet()
client.SetOperator(operatorId, operatorKey)
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.
// Generates a new ECDSA key pair in memory
const newPrivateKey = PrivateKey.generateECDSA();
const newPublicKey = newPrivateKey.publicKey;
// generate an ECDSA key pair in memory
PrivateKey newPrivateKey = PrivateKey.generateECDSA();
PublicKey newPublicKey = newPrivateKey.getPublicKey();
// generate an ECDSA key pair in memory
newPrivateKey, err := hedera.GenerateEcdsaPrivateKey()
newPublicKey := privateKey.PublicKey()
‼️ 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 key (or alias), an optional initial HBAR balance, and once you execute it, the network creates the account and returns the new AccountId in the receipt.
// Build & execute the account creation transaction
const transaction = new AccountCreateTransaction()
.setKey(newPublicKey) // set the account key
.setInitialBalance(new Hbar(20)); // fund with 20 HBAR
const txResponse = await transaction.execute(client);
const receipt = await txResponse.getReceipt(client);
const newAccountId = receipt.accountId;
console.log(`Hedera Account created: ${newAccountId}`);
console.log(`EVM Address: 0x${newPublicKey.toEvmAddress()}`);
// Build & execute the account creation transaction
AccountCreateTransaction transaction = new AccountCreateTransaction()
.setKey(newPublicKey) // set the account key
.setInitialBalance(new Hbar(20)); // fund with 20 HBAR
TransactionResponse txResponse = transaction.execute(client);
TransactionReceipt receipt = txResponse.getReceipt(client);
AccountId newAccountId = receipt.accountId;
System.out.println("Hedera Account created: " + newAccountId);
System.out.println("EVM Address: 0x" + newPublicKey.toEvmAddress());
// Build & execute the account creation transaction
transaction := hedera.NewAccountCreateTransaction().
SetKey(newPublicKey). // set the account key
SetInitialBalance(hedera.NewHbar(20)) // fund with 20 HBAR
// Execute the transaction and get response
txResponse, err := transaction.Execute(client)
if err != nil {
panic(err)
}
// Get the receipt to extract the new account ID
receipt, err := txResponse.GetReceipt(client)
if err != nil {
panic(err)
}
newAccountId := *receipt.AccountID
fmt.Printf("Hedera Account created: %s\n", newAccountId.String())
fmt.Printf("EVM Address: 0x%s\n", 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:
/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.