Hedera
Search…
Create an account

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 the AccountCreateTransaction()API you will need an existing account to pay for the associated transaction fee.
Transaction Signing Requirements
  • The account paying for the transaction fee is required to sign the transaction
Transaction Properties
Field
Description
Key
The key for the new account.
Initial Balance
The initial balance of the account, transferred from the operator account, in Hbar.
Receiver Signature Required
If true, all the account keys must sign any transaction depositing into this account (in addition to all withdrawals).
default: false
Max Automatic Token Associations
Accounts can optionally automatically associate tokens to this account if this property is set. You do not need to associate a token prior to transferring it to this account. The maximum number of auto token associations allowed are 1,000. Please see HIP-23.
Memo
Set a note or description that should be recorded with the state of the account entity (maximum length of 100 characters). Anyone can view this memo on the network.
Auto Renew Period
The period of time in which the account will auto-renew in seconds. The account is charged tinybars for every auto-renew period. Duration type is in seconds. For example, one hour would result in an input value of 3,600 seconds. NOTE: This is fixed to approximately 3 months (7890000 seconds). Any other value will return the following error: AUTORENEW_DURATION_NOT_IN_RANGE.
default: 2,592,000 seconds (DISABLED)
Proxy Account
ID of the account to which this account is proxy staked (DISABLED).
Constructor
Description
new AccountCreateTransaction()
Initializes the AccountCreateTransaction object
1
new AccountCreateTransaction()
Copied!

Methods

V2
V1
Method
Type
Requirement
setKey(<key>)
Key
Required
setInitialBalance(<initialBalance>)
HBar
Optional
setReceiverSignatureRequired(<booleanValue>)
boolean
Optional
setMaxAutomaticTokenAssociations(<amount>)
int
Optional
setAccountMemo(<memo>)
String
Optional
setAutoRenewPeriod(<autoRenewPeriod>)
Duration
Disabled
setProxyAccount(<accountId>)
​AccountId​
Disabled
Java
1
//Create the transaction
2
AccountCreateTransaction transaction = new AccountCreateTransaction()
3
.setKey(privateKey.getPublicKey())
4
.setInitialBalance(new Hbar(1000));
5
​
6
//Submit the transaction to a Hedera network
7
TransactionResponse txResponse = transaction.execute(client);
8
​
9
//Request the receipt of the transaction
10
TransactionReceipt receipt = txResponse.getReceipt(client);
11
​
12
//Get the account ID
13
AccountId newAccountId = receipt.accountId;
14
​
15
System.out.println("The new account ID is " +newAccountId);
16
​
17
//Version 2.0.0
Copied!
JavaScript
1
//Create the transaction
2
const transaction = new AccountCreateTransaction()
3
.setKey(privateKey.publicKey)
4
.setInitialBalance(new Hbar(1000));
5
​
6
//Sign the transaction with the client operator private key and submit to a Hedera network
7
const txResponse = await transaction.execute(client);
8
​
9
//Request the receipt of the transaction
10
const receipt = await txResponse.getReceipt(client);
11
​
12
//Get the account ID
13
const newAccountId = receipt.accountId;
14
​
15
console.log("The new account ID is " +newAccountId);
16
​
17
//v2.0.5
Copied!
Go
1
//Create the transaction
2
transaction := hedera.NewAccountCreateTransaction().
3
SetKey(privateKey.PublicKey()).
4
SetInitialBalance(hedera.NewHbar(1000))
5
​
6
//Sign the transaction with the client operator private key and submit to a Hedera network
7
txResponse, err := AccountCreateTransaction.Execute(client)
8
if err != nil {
9
panic(err)
10
}
11
​
12
//Request the receipt of the transaction
13
receipt, err := txResponse.GetReceipt(client)
14
if err != nil {
15
panic(err)
16
}
17
​
18
//Get the account ID
19
newAccountId := *receipt.AccountID
20
​
21
fmt.Printf("The new account ID is %v\n", newAccountId)
22
​
23
//Version 2.0.0
Copied!
Method
Type
Requirement
setKey(<key>)
Ed25519PubicKey
Required
setInitialBalance(<initialBalance>)
Hbar/long
Optional
setAutoRenewPeriod(<autoRenewPeriod>)
Duration
Disabled
setReceiverSignatureRequired(<booleanValue>)
boolean
Optional
setProxyAccount(<accountId>)
AccountId
Disabled
Java
1
//Create the transaction
2
AccountCreateTransaction transaction = new AccountCreateTransaction()
3
.setKey(newPublicKey)
4
.setInitialBalance(new Hbar(1));
5
​
6
//Sign with the client operator account private key and submit to a Hedera network
7
TransactionId txId = transaction.execute(client);
8
​
9
//Request the receipt of the transaction
10
TransactionReceipt receipt = txId.getReceipt(client);
11
​
12
//Get the new account ID
13
AccountId newAccountId = receipt.getAccountId();
14
​
15
System.out.println("The new account ID is " +newAccountId);
16
​
17
//v1.3.2
Copied!
JavaScript
1
//Create the transaction
2
const transaction = new AccountCreateTransaction()
3
.setKey(newPublicKey)
4
.setInitialBalance(new Hbar(1));
5
​
6
//Sign with the client operator account private key and submit to a Hedera network
7
const txId = await transaction.execute(client);
8
​
9
//Request the receipt of the transaction
10
const receipt = await txId.getReceipt(client);
11
​
12
//Get the new account ID
13
const newAccountId = receipt.getAccountId();
14
​
15
console.log("The new account ID is " +newAccountId);
16
​
17
//v1.4.4
Copied!

Get transaction values

V2
Method
Type
Description
getKey()
Key
Returns the public key on the account
getInitialBalance()
Hbar
Returns the initial balance of the account
getAutoRenewPeriod()
Duration
Returns the auto renew period on the account
getReceiverSignatureRequired()
boolean
Returns whether the receiver signature is required or not
Java
1
//Create an account with 1,000 hbar
2
AccountCreateTransaction transaction = new AccountCreateTransaction()
3
// The only _required_ property here is `key`
4
.setKey(newKey.getPublicKey())
5
.setInitialBalance(new Hbar(1000));
6
​
7
//Return the key on the account
8
Key accountKey = transaction.getKey();
Copied!
JavaScript
1
//Create an account with 1,000 hbar
2
const transaction = new AccountCreateTransaction()
3
// The only _required_ property here is `key`
4
.setKey(newKey.getPublicKey())
5
.setInitialBalance(new Hbar(1000));
6
​
7
//Return the key on the account
8
const accountKey = transaction.getKey();
Copied!
Go
1
//Create an account with 1,000 hbar
2
AccountCreateTransaction := hedera.NewAccountCreateTransaction().
3
SetKey(newKey.PublicKey()).
4
SetInitialBalance(hedera.NewHbar(1000))
5
​
6
//Return the key on the account
7
accountKey, err := AccountCreateTransaction.GetKey()
Copied!

Create an account via an account alias

You can create an account via an account alias. An account alias is a single public key address that is used to create the Hedera account. Hedera supports aliases generated using Ed25519 or ECDSA (secp256k1) algorithms. The account alias is immutable and cannot be modified.
The account is officially registered with Hedera when hbars are initially deposited to the account alias. The transaction fee to create the account is deducted from the initial hbar transfer. The remaining balance minus the transaction fee to create the account is the initial balance of the new account. The account create transaction is executed first to register the new account and following the transfer transaction to transfer the remaining hbar balance to the new account.
The consensus timestamp for the create account transaction is one nanosecond before the transfer transaction. The parent transfer transaction and the child account create transaction share the same payer account and timestamp in the transaction ID except that the child transaction has an added nonce value. You will also notice the account and transaction memo set to auto-created account.
You can return the new account ID from one of the following ways:
  • Requesting the child records of the parent transfer transaction using the parent transfer transaction ID. The child transaction ID in the child transaction record will display a nonce value ([email protected]/1).
  • Requesting the child receipts of the parent transfer transaction using the parent transfer transaction ID. The account ID field will be populated with the new account ID.
  • Requesting the receipt or record of the account create transaction by using the transaction ID of the parent transfer transaction and setting the nonce value to 1
  • Requesting an account info using the account alias (known issue)
  • Looking at the parent transfer transaction record transfer list for the account that has a transfer that equals the transfer value minus the transaction fee
Note: You cannot get the new account ID from the receipt of the transfer transaction like you would expect from a normal account create transaction that was not triggered by another transaction. You can use the alias in transfer transactions, account info and balance queries. The feature will be enabled to support all other transactions and queries in a future release.
Transaction Signing Requirements
  • The account key paying for the transfer transaction fee
  • The account the hbars are being debited from the transfer transaction
Last modified 19d ago