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 the base transaction fee

  • Please use the Hedera fee estimator to estimate your transaction fee cost

Transaction Signing Requirements

  • The account that is being deleted is required to sign the transaction

Methods

MethodTypeDescriptionRequirement

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

//Create the transaction to delete an account
AccountDeleteTransaction transaction = new AccountDeleteTransaction()
    .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 network
TransactionResponse  txResponse = transaction.freezeWith(client).sign(newKey).execute(client);

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

//Get the transaction consensus status
Status transactionStatus = receipt.status;

System.out.println("The transaction consensus status is " +transactionStatus);

Get transaction values

MethodTypeDescription

getAccountId(<accountId>)

AccountId

The account to delete

getTransferAccountId(<transferAccountId>)

AccountId

The account to transfer the remaining funds to

//Create the transaction to delete an account
AccountDeleteTransaction transaction = new AccountDeleteTransaction()
    .setAccountId(newAccountId)
    .setTransferAccountId(OPERATOR_ID);

//Get the account ID from the transaction
AccountId transactionAccountId = transaction.getAccountId()

System.out.println("The account to be deleted in this transaction is " +transactionAccountId)

//v2.0.0

Last updated