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

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

File Properties

new FileUpdateTransaction()

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.

Java
//Create the transaction
FileUpdateTransaction transaction = new FileUpdateTransaction()
    .addKey(newPublicKey)
    .setFileId(newFileId);

//Modify the default max transaction fee from 1 hbar to 2 hbars
FileUpdateTransaction txFee = transaction.setMaxTransactionFee(new Hbar(3));

//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
TransactionId txId = txFee.build(client).sign(key).sign(newKey).execute(client);

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

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

System.out.println("The transaction consensus status is " +transactionStatus);
JavaScript
//Create the transaction
const transaction = new FileUpdateTransaction()
    .addKey(newPublicKey)
    .setFileId(newFileId);

//Modify the default max transaction fee from 1 hbar to 2 hbars
const txFee = transaction.setMaxTransactionFee(new Hbar(3));

//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
const txId = await txFee.build(client).sign(key).sign(newKey).execute(client);

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

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

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

Get transaction values

Java
//Create the transaction
FileUpdateTransaction transaction = new FileUpdateTransaction()
    .setFileId(fileId)
    .setKeys(newKey);

//Get the contents of a file
Key getKey = transaction.getKey();

//v2.0.0
JavaScript
//Create the transaction
const transaction = new FileUpdateTransaction()
    .setFileId(newFileId);

//Get the contents of a file
const getKey = transaction.getKey();
Go
//Create the transaction
transaction := hedera.NewFileUpdateTransaction().
      SetFileID(fileId).
        SetKeys(newKey)

//Get the contents of a file
getKey := transaction.GetKeys()

//v2.0.0

Last updated