Delete a file

A transaction that deletes a file from a Hedera network. When deleted, a file's contents are truncated to zero length and it can no longer be updated or appended to, or its expiration time extended. When you request the contents or info of a deleted file, the network will return FILE_DELETED.

Transaction Signing Requirements

  • The key(s) on the file are required to sign the transaction

  • If you do not sign with the key(s) on the file, you will receive an INVALID_SIGNATURE network error

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

ConstructorDescription

new FileDeleteTransaction()

Initializes the FileDeleteTransaction object

new FileDeleteTransaction()

Methods

MethodTypeDescription

setFileId(<fileId>)

FileId

The ID of the file to delete in x.y.z format

Java
FileDeleteTransaction transaction = new FileDeleteTransaction()
    .setFileId(newFileId);

//Change the default transaction fee to 2 hbars
FileDeleteTransaction newMaxFee = transaction.setMaxTransactionFee(new Hbar(2));

//Prepare transaction for signing, sign with the key on the file, sign with the client operator key and submit to a Hedera network
TransactionId txId = newMaxFee.build(client).sign(key).execute(client);

//Request the receipt
TransactionReceipt receipt = txId.getReceipt(client);

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

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

//v1.3.2
JavaScript
const transaction = new FileDeleteTransaction()
    .setFileId(newFileId);

//Change the default transaction fee to 2 hbars
const newMaxFee = transaction.setMaxTransactionFee(new Hbar(2));

//Prepare transaction for signing, sign with the key on the file, sign with the client operator key and submit to a Hedera network
const txId = await newMaxFee.build(client).sign(key).execute(client);

//Request the receipt
const receipt = await txId.getReceipt(client);

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

console.log("The transaction consensus status is " + transactionStatus);

//v1.4.4 (issue: returns unauthorized)

Get transaction values

MethodTypeDescription

getFileId(<fileId>)

FileId

The ID of the file to delete (x.z.y)

Java
//Create the transaction
FileDeleteTransaction transaction = new FileDeleteTransaction()
    .setFileId(newFileId);

//Get the file ID
FileId getFileId = transaction.getFileId();
JavaScript
//Create the transaction
const transaction = new FileDeleteTransaction()
    .setFileId(newFileId);
    
//Get the file ID
FileId getFileId = transaction.getFileId();
Go
//Create the transaction
transaction := hedera.NewFileDeleteTransaction().
	  SetFileID(fileId)
	
//Get the file ID
getFileId := transaction.GetFileID()

Last updated