Skip to main content

Create an account using the account create API

A transaction that creates a Hedera account. A Hedera account is required to interact with any of the Hedera network services as you need an account to pay for all associated transaction/query fees. You can visit the Hedera Developer Portal to create a previewnet or testnet account. You can also use third-party wallets to generate free mainnet accounts. To process an account create transaction, you will need an existing account to pay for the transaction fee. To obtain the new account ID, request the receipt of the transaction.
When creating a new account using theAccountCreateTransaction()API you will need an existing account to pay for the associated transaction fee.
Account Properties

Account Properties

Transaction Fees
  • The sender pays for the token association fee and the rent for the first auto-renewal period.
  • Please see the transaction and query fees table for the base transaction fee.
  • Please use the Hedera fee estimator to estimate your transaction fee cost.
Transaction Signing Requirements
  • The account paying for the transaction fee is required to sign the transaction.

Maximum Auto-Associations and Fees

Accounts have a property, maxAutoAssociations, and the property’s value determines the maximum number of automatic token associations allowed.
Property ValueDescription
0Automatic token associations or token airdrops are not allowed, and the account must be manually associated with a token. This also applies if the value is less than or equal to usedAutoAssociations.
-1Unlimited automatic token associations are allowed, and this is the default for accounts created via auto account creation and for accounts that began as hollow accounts and are now complete. Accounts with -1 can receive new tokens without manually associating them. The sender still pays the maxAutoAssociations fee and initial rent for each association.
> 0If the value is a positive number (number greater than 0), the number of automatic token associations an account can have is limited to that number.
The sender pays the maxAutoAssociations fee and the rent for the first auto-renewal period for the association. This is in addition to the typical transfer fees. This ensures the receiver can receive tokens without association and makes it a smoother transfer process.
Reference: HIP-904

Methods

MethodTypeRequirement
setKey(<key>)KeyRequired
setAlias(<alias>)EvmAddressOptional
setInitialBalance(<initialBalance>)HBarOptional
setReceiverSignatureRequired(<booleanValue>)booleanOptional
setMaxAutomaticTokenAssociations(<amount>)intOptional
setStakedAccountId(<stakedAccountId>)AccountIdOptional
setStakedNodeId(<stakedNodeId>)longOptional
setDeclineStakingReward(<declineStakingReward>)booleanOptional
setAccountMemo(<memo>)StringOptional
setAutoRenewPeriod(<autoRenewPeriod>)DurationDisabled
addHook(<hook>)HookCreationDetailsOptional
setHooks(<hooks>)list<HookCreationDetails>Optional
Account AliasIf an alias is set during account creation, it becomes immutable, meaning it cannot be changed. If you plan to update or rotate keys in the future, do not set the alias at the time of initial account creation. The alias can be set after finalizing all key updates.
Account Hooks (HIP-1195)You can attach Hiero Hooks to an account at creation time using addHook(). Hooks are programmable EVM extension points that let you enforce custom validation logic on transfers involving this account. See Create and Manage Hooks for full details and utility class reference.
//Create the transaction
AccountCreateTransaction transaction = new AccountCreateTransaction()
    .setKeyWithAlias(ecdsaPublicKey)
    // DO NOT set an alias with your key if you plan to update/rotate keys in the future, Use .setKeyWithoutAlias instead 
    // .setKeyWithoutAlias(ecdsaPublicKey)
    .setInitialBalance(new Hbar(1));

//Submit the transaction to a Hedera network
TransactionResponse txResponse = transaction.execute(client);

//Request the receipt of the transaction
TransactionReceipt receipt = txResponse.getReceipt(client);

//Get the account ID
AccountId newAccountId = receipt.accountId;

System.out.println("The new account ID is " +newAccountId);

//Version 2.0.0

Create an account with an EVM hook

This example creates a new account with an account allowance hook attached. The hook contract must be deployed first via ContractCreateTransaction.
// Step 1: Deploy hook contract first (standard ContractCreateTransaction)
ContractId contractId = /* ... your deployed hook contract ... */;

// Step 2: Create the hook details
HookCreationDetails hookDetails = new HookCreationDetails(
    HookExtensionPoint.ACCOUNT_ALLOWANCE_HOOK,
    1002L,
    new EvmHook(contractId),
    adminKey.getPublicKey()
);

// Step 3: Create the account with the hook attached
TransactionResponse txResponse = new AccountCreateTransaction()
    .setKey(accountKey.getPublicKey())
    .setInitialBalance(Hbar.from(1))
    .addHook(hookDetails)
    .setMaxTransactionFee(new Hbar(10))
    .freezeWith(client)
    .sign(accountKey)
    .execute(client);

AccountId newAccountId = txResponse.getReceipt(client).accountId;
System.out.println("Account created with hook: " + newAccountId);

Get transaction values

MethodTypeDescription
getKey()KeyReturns the public key on the account
getInitialBalance()HbarReturns the initial balance of the account
getAutoRenewPeriod()DurationReturns the auto renew period on the account
getDeclineStakingReward()booleanReturns whether or not the account declined rewards
getStakedNodeId()longReturns the node ID
getStakedAccountId()AccountIdReturns the node account ID
getReceiverSignatureRequired()booleanReturns whether the receiver signature is required or not
getHooks()list<HookCreationDetails>Returns the hooks to be created with the account
//Create an account with 1 hbar
AccountCreateTransaction transaction = new AccountCreateTransaction()
    // The only _required_ property here is `key`
    .setKeyWithAlias(newPublicKey)
    // DO NOT set an alias with your key if you plan to update/rotate keys in the future, Use .setKeyWithoutAlias instead 
    // .setKeyWithoutAlias(newPublicKey)
    .setInitialBalance(new Hbar(1));

//Return the key on the account
Key accountKey = transaction.getKey();