Hedera
Search…
Update a file
A transaction that updates the state of an existing file on a Hedera network. Once the transaction has been processed, the network will be updated with the new field values of the file. If you need to access a previous state of the file, you can query a mirror node.
Transaction Signing Requirements
    The key or keys on the file are required to sign this transaction to modify the file properties
    If you are updating the keys on the file, you must sign with the old key and the new key
    If you do not sign with the key(s) on the file, you will receive an INVALID_SIGNATURE network error

File Properties

Field
Description
Key(s)
Update the keys which must sign any transactions modifying this file. All keys must sign to modify the file's contents or keys. No key is required to sign for extending the expiration time (except the one for the operator account paying for the transaction). The network currently requires a file to have at least one key (or key list or threshold key) but this requirement may be lifted in the future.
Contents
The content to update the files with.
Expiration Time
If set, update the expiration time of the file. Must be in the future (may only be used to extend the expiration). To make a file inaccessible use FileDeleteTransaction.
Memo
Short publicly visible memo about the file. No guarantee of uniqueness. (100 characters max)
Constructor
Description
new FileUpdateTransaction()
Initializes the FileUpdateTransaction object
1
new FileUpdateTransaction()
Copied!

Methods

Note: The total size for a given transaction is limited to 6KiB. If you exceed this value you will need to submit a FileUpdateTransaction that is less than 6KiB and then submit a FileAppendTransaction to add the remaining content to the file.
V2
V1
Method
Type
Requirement
setFileId(<fileId>)
FileId
Required
setKey(<keys>)
Key
Optional
setContents(<bytes>)
byte [ ]
Optional
setContents(<text>)
String
Optional
setExpirationTime(<expiration>)
Instant
Optional
setFileMemo(<memo>)
String
Optional
Java
1
//Create the transaction
2
FileUpdateTransaction transaction = new FileUpdateTransaction()
3
.setFileId(fileId)
4
.setKeys(newKey);
5
6
//Modify the max transaction fee
7
FileUpdateTransaction txFee = transaction.setMaxTransactionFee(new Hbar(3));
8
9
//Freeze the transaction, sign with the original key, sign with the new key, sign with the client operator key and submit the transaction to a Hedera network
10
TransactionResponse txResponse = txFee.freezeWith(client).sign(fileKey).sign(newKey).execute(client);
11
12
//Get the receipt of the transaction
13
TransactionReceipt receipt = txResponse.getReceipt(client);
14
15
//Get the transaction consensus status
16
Status transactionStatus = receipt.status;
17
18
System.out.println("The transaction consensus status is " +transactionStatus);
19
20
//v2.0.0
Copied!
JavaScript
1
//Create the transaction
2
const transaction = await new FileUpdateTransaction()
3
.setFileId(fileId)
4
.setContents("The new contents")
5
.setMaxTransactionFee(new Hbar(2))
6
.freezeWith(client);
7
8
//Sign with the file private key
9
const signTx = await transaction.sign(fileKey);
10
11
//Sign with the client operator private key and submit to a Hedera network
12
const submitTx = await signTx.execute(client);
13
14
//Request the receipt
15
const receipt = await submitTx.getReceipt(client);
16
17
//Get the transaction consensus status
18
const transactionStatus = receipt.status;
19
20
console.log("The transaction consensus status " +transactionStatus3.toString());
21
22
//v2.0.5
Copied!
Go
1
//Create the transaction
2
transaction := hedera.NewFileUpdateTransaction().
3
SetFileID(fileId).
4
SetKeys(newKey)
5
6
//Modify the max transaction fee
7
modifyMaxTransactionFee := transaction.SetMaxTransactionFee(hedera.HbarFrom(2, hedera.HbarUnits.Hbar))
8
9
//Prepare the transaction for signing
10
freezeTransaction, err := modifyMaxTransactionFee.FreezeWith(client)
11
if err != nil {
12
panic(err)
13
}
14
15
//Sign with the key on the file, sign with the client operator key and submit to a Hedera network
16
txResponse, err := freezeTransaction.Sign(fileKey).Sign(newKey).Execute(client)
17
if err != nil {
18
panic(err)
19
}
20
21
//Request the receipt
22
receipt, err := txResponse.GetReceipt(client)
23
if err != nil {
24
panic(err)
25
}
26
27
//Get the transaction status
28
transactionStatus := receipt.Status
29
30
fmt.Println("The transaction consensus status is ", transactionStatus)
31
32
//v2.0.0
Copied!
Method
Type
Requirement
setFileId(<fileId>)
FileId
Required
addKey(<keys>)
PublicKey
Optional
setContents(<bytes>)
byte [ ]
Optional
setContents(<text>)
String
Optional
setExpirationTime(<expiration>)
Instant
Optional
Java
1
//Create the transaction
2
FileUpdateTransaction transaction = new FileUpdateTransaction()
3
.addKey(newPublicKey)
4
.setFileId(newFileId);
5
6
//Modify the default max transaction fee from 1 hbar to 2 hbars
7
FileUpdateTransaction txFee = transaction.setMaxTransactionFee(new Hbar(3));
8
9
//Build the transaction, sign with the original key, sign with the new key, sign with the client operator key and submit the transaction to a Hedera network
10
TransactionId txId = txFee.build(client).sign(key).sign(newKey).execute(client);
11
12
//Request the receipt of the transaction
13
TransactionReceipt receipt = txId.getReceipt(client);
14
15
//Get the transaction consensus status
16
Status transactionStatus = receipt.status;
17
18
System.out.println("The transaction consensus status is " +transactionStatus);
Copied!
JavaScript
1
//Create the transaction
2
const transaction = new FileUpdateTransaction()
3
.addKey(newPublicKey)
4
.setFileId(newFileId);
5
6
//Modify the default max transaction fee from 1 hbar to 2 hbars
7
const txFee = transaction.setMaxTransactionFee(new Hbar(3));
8
9
//Build the transaction, sign with the original key, sign with the new key, sign with the client operator key and submit the transaction to a Hedera network
10
const txId = await txFee.build(client).sign(key).sign(newKey).execute(client);
11
12
//Request the receipt of the transaction
13
const receipt = await txId.getReceipt(client);
14
15
//Get the transaction consensus status
16
const transactionStatus = receipt.status;
17
18
console.log("The transaction consensus status is " +transactionStatus);
Copied!

Get transaction values

V2
Method
Type
Requirement
getFileId()
FileId
Optional
getKey()
Key
Optional
setContents()
ByteString
Optional
getExpirationTime()
Instant
Optional
getFileMemo()
String
Optional
Java
1
//Create the transaction
2
FileUpdateTransaction transaction = new FileUpdateTransaction()
3
.setFileId(fileId)
4
.setKeys(newKey);
5
6
//Get the contents of a file
7
Key getKey = transaction.getKey();
8
9
//v2.0.0
Copied!
JavaScript
1
//Create the transaction
2
const transaction = new FileUpdateTransaction()
3
.setFileId(newFileId);
4
5
//Get the contents of a file
6
const getKey = transaction.getKey();
Copied!
Go
1
//Create the transaction
2
transaction := hedera.NewFileUpdateTransaction().
3
SetFileID(fileId).
4
SetKeys(newKey)
5
6
//Get the contents of a file
7
getKey := transaction.GetKeys()
8
9
//v2.0.0
Copied!
Last modified 6d ago