Hedera
Search…
Delete an account
A transaction that deletes an existing account from the Hedera network. Before deleting an account, the existing hbars must be transferred to another account. If you fail to transfer the hbars, you will receive an error message "setTransferAccountId() required." Transfers cannot be made into a deleted account. A record of the deleted account will remain in the ledger until it expires.The expiration of a deleted account can be extended. The account that is being deleted is required to sign the transaction.
Transaction Fees
  • Please see the transaction and query fees table for base transaction fee
  • Please use the Hedera fee estimator to estimate your transaction fee cost
Transaction Signing Requirements
  • The account the is being deleted is required to sign the transaction
Constructor
Description
new AccountDeleteTransaction()
Initializes the AccountDeleteTransaction object
1
new AccountDeleteTransaction()
Copied!

Methods

V2
V1
Method
Type
Description
Requirement
setAccountId(<accountId>)
AccountId
The ID of the account to delete.
Required
setTransferAccountId(<transferAccountId>)
AccountId
The ID of the account to transfer the remaining funds to.
Optional
Java
1
//Create the transaction to delete an account
2
AccountDeleteTransaction transaction = new AccountDeleteTransaction()
3
.setAccountId(accountId)
4
.setTransferAccountId(OPERATOR_ID);
5
​
6
//Freeze the transaction for signing, sign with the private key of the account that will be deleted, sign with the operator key and submit to a Hedera network
7
TransactionResponse txResponse = transaction.freezeWith(client).sign(newKey).execute(client);
8
​
9
//Request the receipt of the transaction
10
TransactionReceipt receipt = txResponse.getReceipt(client);
11
​
12
//Get the transaction consensus status
13
Status transactionStatus = receipt.status;
14
​
15
System.out.println("The transaction consensus status is " +transactionStatus);
Copied!
JavaScript
1
//Create the transaction to delete an account
2
const transaction = await new AccountDeleteTransaction()
3
.setAccountId(accountId)
4
.setTransferAccountId(OPERATOR_ID)
5
.freezeWith(client);
6
​
7
//Sign the transaction with the account key
8
const signTx = await transaction.sign(accountKey);
9
​
10
//Sign with the client operator private key and submit to a Hedera network
11
const txResponse = await signTx.execute(client);
12
​
13
//Request the receipt of the transaction
14
const receipt = await txResponse.getReceipt(client);
15
​
16
//Get the transaction consensus status
17
const transactionStatus = receipt.status;
18
​
19
console.log("The transaction consensus status is " +transactionStatus);
20
​
21
//2.0.5
Copied!
Go
1
//Create the transaction to delete an account, freeze the transaction for signing
2
transaction, err := hedera.NewAccountDeleteTransaction().
3
SetAccountID(newAccountID).
4
SetTransferAccountID(operatorAccountID).
5
FreezeWith(client)
6
if err != nil {
7
panic(err)
8
}
9
​
10
//Sign with the private key of the account that will be deleted, sign with the operator key and submit to a Hedera network
11
txResponse, err := transaction.Sign(accountKey).Execute(client)
12
if err != nil {
13
panic(err)
14
}
15
​
16
//Request the receipt of the transaction
17
receipt, err := txResponse.GetReceipt(client)
18
if err != nil {
19
panic(err)
20
}
21
​
22
//Get the transaction consensus status
23
transactionStatus := receipt.Status
24
​
25
fmt.Printf("The transaction consensus status is %v\n", transactionStatus)
26
​
27
//v2.0.0
Copied!
Method
Type
Description
Requirement
setAccountId(<accountId>)
AccountId
The ID of the account to delete.
Required
setTransferAccountId(<transferAccountId>)
AccountId
The ID of the account to transfer the remaining funds to.
Optional
Java
1
//Create the transaction
2
AccountDeleteTransaction transaction = new AccountDeleteTransaction()
3
.setDeleteAccountId(accountId)
4
.setTransferAccountId(OPERATOR_ID);
5
​
6
//Build the unsigned transaction, sign with account key, sign with the client operator account private key and submit to a Hedera network
7
TransactionId txId = transaction.build(client).sign(newKey).execute(client);
8
​
9
//Request the receipt of the transaction
10
TransactionReceipt receipt = txId.getReceipt(client);
11
​
12
//Get the transaction consensus status
13
Status transactionStatus = receipt.status;
14
​
15
System.out.println("The transaction consensus status is " +transactionStatus);
16
​
17
//v1.3.2
Copied!
JavaScript
1
//Create the transaction
2
const transaction = await new AccountDeleteTransaction()
3
.setDeleteAccountId(accountId)
4
.setTransferAccountId(OPERATOR_ID)
5
.build(client);
6
​
7
//Sign the transaction with the account key
8
const signTx = await transaction.sign(accountKey);
9
​
10
//Sign with the client operator private key and submit to a Hedera network
11
const txId = await signTx.execute(client);
12
​
13
//Request the receipt of the transaction
14
const receipt = await txId.getReceipt(client);
15
​
16
//Get the transaction consensus status
17
const transactionStatus = receipt.status;
18
​
19
console.log("The transaction consensus status is " +transactionStatus);
Copied!

Get transaction values

V2
Method
Type
Description
getAccountId(<accountId>)
AccountId
The account to delete
getTransferAccountId(<transferAccountId>)
AccountId
The account to transfer the remaining funds to
Java
1
//Create the transaction to delete an account
2
AccountDeleteTransaction transaction = new AccountDeleteTransaction()
3
.setAccountId(newAccountId)
4
.setTransferAccountId(OPERATOR_ID);
5
​
6
//Get the account ID from the transaction
7
AccountId transactionAccountId = transaction.getAccountId()
8
​
9
System.out.println("The account to be deleted in this transaction is " +transactionAccountId)
10
​
11
//v2.0.0
Copied!
JavaScript
1
//Create the transaction to delete an account
2
const transaction = new AccountDeleteTransaction()
3
.setAccountId(newAccountId)
4
.setTransferAccountId(OPERATOR_ID);
5
​
6
//Get the account ID from the transaction
7
const transactionAccountId = transaction.getAccountId()
8
​
9
console.log("The account to be deleted in this transaction is " +transactionAccountId)
Copied!
Go
1
//Create the transaction to delete an account
2
transaction, err := hedera.NewAccountDeleteTransaction().
3
SetAccountID(newAccountID).
4
SetTransferAccountID(operatorAccountID)
5
​
6
//Get the account ID from the transaction
7
transactionAccountId := transaction.GetAccountID()
8
​
9
//v2.0.0
Copied!