A transaction that deletes an existing account from the Hedera network. Before deleting an account, the existing HBAR must be transferred to another account. Submitting a transaction to delete an account without assigning a beneficiary via setTransferAccountId() will result in a ACCOUNT_ID_DOES_NOT_EXIST error. 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.
Note: The setTransferAccountId() method is required, regardless of whether the account has a zero balance.
Transaction Fees
Please see the transaction and query fees table for the base transaction fee.
The account that is being deleted is required to sign the transaction.
Methods
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.
Required
//Create the transaction to delete an accountAccountDeleteTransaction transaction =newAccountDeleteTransaction().setAccountId(accountId).setTransferAccountId(OPERATOR_ID);//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 networkTransactionResponse txResponse =transaction.freezeWith(client).sign(newKey).execute(client);//Request the receipt of the transactionTransactionReceipt receipt =txResponse.getReceipt(client);//Get the transaction consensus statusStatus transactionStatus =receipt.status;System.out.println("The transaction consensus status is "+transactionStatus);
//Create the transaction to delete an accountconsttransaction=awaitnewAccountDeleteTransaction().setAccountId(accountId).setTransferAccountId(OPERATOR_ID).freezeWith(client);//Sign the transaction with the account keyconstsignTx=awaittransaction.sign(accountKey);//Sign with the client operator private key and submit to a Hedera networkconsttxResponse=awaitsignTx.execute(client);//Request the receipt of the transactionconstreceipt=awaittxResponse.getReceipt(client);//Get the transaction consensus statusconsttransactionStatus=receipt.status;console.log("The transaction consensus status is "+transactionStatus);//2.0.5
//Create the transaction to delete an account, freeze the transaction for signingtransaction, err :=hedera.NewAccountDeleteTransaction().SetAccountID(newAccountID).SetTransferAccountID(operatorAccountID).FreezeWith(client)if err != nil {panic(err)}//Sign with the private key of the account that will be deleted, sign with the operator key and submit to a Hedera networktxResponse, err :=transaction.Sign(accountKey).Execute(client)if err != nil {panic(err)}//Request the receipt of the transactionreceipt, err :=txResponse.GetReceipt(client)if err != nil {panic(err)}//Get the transaction consensus statustransactionStatus :=receipt.Statusfmt.Printf("The transaction consensus status is %v\n", transactionStatus)//v2.0.0
Get transaction values
Method
Type
Description
getAccountId(<accountId>)
AccountId
The account to delete
getTransferAccountId(<transferAccountId>)
AccountId
The account to transfer the remaining funds to
//Create the transaction to delete an accountAccountDeleteTransaction transaction =newAccountDeleteTransaction().setAccountId(newAccountId).setTransferAccountId(OPERATOR_ID);//Get the account ID from the transactionAccountId transactionAccountId =transaction.getAccountId()System.out.println("The account to be deleted in this transaction is "+transactionAccountId)//v2.0.0
//Create the transaction to delete an accountconst transaction =newAccountDeleteTransaction().setAccountId(newAccountId).setTransferAccountId(OPERATOR_ID);//Get the account ID from the transactionconst transactionAccountId =transaction.getAccountId()console.log("The account to be deleted in this transaction is "+transactionAccountId)
//Create the transaction to delete an accounttransaction, err :=hedera.NewAccountDeleteTransaction().SetAccountID(newAccountID).SetTransferAccountID(operatorAccountID)//Get the account ID from the transactiontransactionAccountId :=transaction.GetAccountID()//v2.0.0