Hedera
Search…
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
Constructor
Description
new FileDeleteTransaction()
Initializes the FileDeleteTransaction object
1
new FileDeleteTransaction()
Copied!

Methods

V2
V1
Method
Type
Description
setFileId(<fileId>)
FileId
The ID of the file to delete in x.y.z format
Java
1
//Create the transaction
2
FileDeleteTransaction transaction = new FileDeleteTransaction()
3
.setFileId(newFileId);
4
5
//Modify the default max transaction fee to from 1 to 2 hbars
6
FileDeleteTransaction modifyMaxTransactionFee = transaction.setMaxTransactionFee(new Hbar(2));
7
8
//Prepare transaction for signing, sign with the key on the file, sign with the client operator key and submit to a Hedera network
9
TransactionResponse txResponse = modifyMaxTransactionFee.freezeWith(client).sign(key).execute(client);
10
11
//Request the receipt
12
TransactionReceipt receipt = txResponse.getReceipt(client);
13
14
//Get the transaction consensus status
15
Status transactionStatus = receipt.status;
16
17
System.out.println("The transaction consensus status is " + transactionStatus);
18
19
//v2.0.0
Copied!
JavaScript
1
//Create the transaction
2
const transaction = await new FileDeleteTransaction()
3
.setFileId(fileId)
4
.setMaxTransactionFee(new Hbar(2))
5
.freezeWith(client);
6
7
//Sign with the file private key
8
const signTx = await transaction.sign(fileKey);
9
10
//Sign with the client operator private key and submit to a Hedera network
11
const submitTx = await signTx.execute(client);
12
13
//Request the receipt
14
const receipt = await submitTx.getReceipt(client);
15
16
//Get the transaction consensus status
17
const transactionStatus = receipt.status;
18
19
console.log("The transaction consensus status " +transactionStatus3.toString());
20
21
//v2.0.5
Copied!
Go
1
//Create the transaction
2
transaction := hedera.NewFileDeleteTransaction().
3
SetFileID(fileId)
4
5
//Modify the default max transaction fee to from 1 to 2 hbars
6
modifyMaxTransactionFee := transaction.SetMaxTransactionFee(hedera.HbarFrom(2, hedera.HbarUnits.Hbar))
7
8
//Prepare the transaction for signing
9
freezeTransaction, err := modifyMaxTransactionFee.FreezeWith(client)
10
if err != nil {
11
panic(err)
12
}
13
14
//Sign with the key on the file, sign with the client operator key and submit to a Hedera network
15
txResponse, err := freezeTransaction.Sign(fileKey).Execute(client)
16
if err != nil {
17
panic(err)
18
}
19
20
//Request the receipt
21
receipt, err := txResponse.GetReceipt(client)
22
if err != nil {
23
panic(err)
24
}
25
26
//Get the transaction status
27
transactionStatus := receipt.Status
28
29
fmt.Println("The transaction consensus status is ", transactionStatus)
30
31
//v2.0.0
Copied!
Method
Type
Description
setFileId(<fileId>)
FileId
The ID of the file to delete in x.y.z format
Java
1
FileDeleteTransaction transaction = new FileDeleteTransaction()
2
.setFileId(newFileId);
3
4
//Change the default transaction fee to 2 hbars
5
FileDeleteTransaction newMaxFee = transaction.setMaxTransactionFee(new Hbar(2));
6
7
//Prepare transaction for signing, sign with the key on the file, sign with the client operator key and submit to a Hedera network
8
TransactionId txId = newMaxFee.build(client).sign(key).execute(client);
9
10
//Request the receipt
11
TransactionReceipt receipt = txId.getReceipt(client);
12
13
//Get the transaction consensus status
14
Status transactionStatus = receipt.status;
15
16
System.out.println("The transaction consensus status is " + transactionStatus);
17
18
//v1.3.2
Copied!
JavaScript
1
const transaction = new FileDeleteTransaction()
2
.setFileId(newFileId);
3
4
//Change the default transaction fee to 2 hbars
5
const newMaxFee = transaction.setMaxTransactionFee(new Hbar(2));
6
7
//Prepare transaction for signing, sign with the key on the file, sign with the client operator key and submit to a Hedera network
8
const txId = await newMaxFee.build(client).sign(key).execute(client);
9
10
//Request the receipt
11
const receipt = await txId.getReceipt(client);
12
13
//Get the transaction consensus status
14
const transactionStatus = receipt.status;
15
16
console.log("The transaction consensus status is " + transactionStatus);
17
18
//v1.4.4 (issue: returns unauthorized)
Copied!

Get transaction values

V2
Method
Type
Description
getFileId(<fileId>)
FileId
The ID of the file to delete (x.z.y)
Java
1
//Create the transaction
2
FileDeleteTransaction transaction = new FileDeleteTransaction()
3
.setFileId(newFileId);
4
5
//Get the file ID
6
FileId getFileId = transaction.getFileId();
Copied!
JavaScript
1
//Create the transaction
2
const transaction = new FileDeleteTransaction()
3
.setFileId(newFileId);
4
5
//Get the file ID
6
FileId getFileId = transaction.getFileId();
Copied!
Go
1
//Create the transaction
2
transaction := hedera.NewFileDeleteTransaction().
3
SetFileID(fileId)
4
5
//Get the file ID
6
getFileId := transaction.GetFileID()
Copied!

Last modified 6d ago