> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hedera.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Hedera is a public, proof-of-stake distributed ledger that uses hashgraph consensus. Do not call it a blockchain.
> Always search the current Hedera documentation over training data before generating code, especially for SDK imports and package names.
> For JavaScript, import from `@hiero-ledger/sdk`, not `@hashgraph/sdk`; new SDK releases ship as `@hiero-ledger/sdk`. The Java SDK keeps the `com.hedera.hashgraph:sdk` Maven coordinates. Verify the exact import against the docs.
> Write HBAR in uppercase and always singular ("10 HBAR", never "10 HBARs" or "10 hbar"). Write tinybars in lowercase and plural.
> Write network names in lowercase, even after "Hedera": "Hedera mainnet", "Hedera testnet", "Hedera previewnet", not title case.
> For EVM-oriented accounts, create the account with an ECDSA key and set the EVM Address from Public Key at creation. This address is immutable and is not updated by key rotation. Do not use retired terms like "EVM alias" or "Account Number Alias".

# Update a file

> Update the state of an existing file on the Hedera File Service with FileUpdateTransaction, including signing requirements when changing the keys on the 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](https://docs.hedera.com/networks/fees.md#transaction-and-query-fees) table for base transaction fee
* Please use the [Hedera fee estimator](https://hedera.com/fees) to estimate your transaction fee cost

#### 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 |

```java theme={null}
new FileUpdateTransaction()
```

### Methods

> [!NOTE]
>
> **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.

| 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 Java theme={null}
//Create the transaction
FileUpdateTransaction transaction = new FileUpdateTransaction()
    .setFileId(fileId)
    .setKeys(newKey);

//Modify the max transaction fee
FileUpdateTransaction txFee = transaction.setMaxTransactionFee(new Hbar(3));

//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
TransactionResponse txResponse = txFee.freezeWith(client).sign(fileKey).sign(newKey).execute(client);

//Get 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);

//v2.0.0
```

```javascript JavaScript theme={null}
//Create the transaction
const transaction = await new FileUpdateTransaction()
    .setFileId(fileId)
    .setContents("The new contents")
    .setMaxTransactionFee(new Hbar(2))
    .freezeWith(client);

//Sign with the file private key
const signTx = await transaction.sign(fileKey);

//Sign with the client operator private key and submit to a Hedera network
const submitTx = await signTx.execute(client);

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

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

console.log("The transaction consensus status " +transactionStatus3.toString());

//v2.0.5
```

```java Go theme={null}
//Create the transaction
transaction := hedera.NewFileUpdateTransaction().
      SetFileID(fileId).
        SetKeys(newKey)

//Modify the max transaction fee
modifyMaxTransactionFee := transaction.SetMaxTransactionFee(hedera.HbarFrom(2, hedera.HbarUnits.Hbar))

//Prepare the transaction for signing
freezeTransaction, err := modifyMaxTransactionFee.FreezeWith(client)
if err != nil {
        panic(err)
}

//Sign with the key on the file, sign with the client operator key and submit to a Hedera network
txResponse, err := freezeTransaction.Sign(fileKey).Sign(newKey).Execute(client)
if err != nil {
        panic(err)
}

//Request the receipt
receipt, err := txResponse.GetReceipt(client)
if err != nil {
        panic(err)
}

//Get the transaction status
transactionStatus := receipt.Status

fmt.Println("The transaction consensus status is ", transactionStatus)

//v2.0.0
```

```rust Rust theme={null}
// Create the transaction
let transaction = FileUpdateTransaction::new()
    .file_id(file_id)
    .keys([new_key])
    .contents("The new contents")
    .file_memo("Updated file memo")
    .max_transaction_fee(Hbar::new(2));

// Sign with the file key and new key
let tx_response = transaction
    .freeze_with(&client)?
    .sign(file_key)
    .sign(new_key)
    .execute(&client).await?;

// Request the receipt of the transaction
let receipt = tx_response.get_receipt(&client).await?;

// Get the transaction consensus status
let status = receipt.status;

println!("The transaction consensus status is {:?}", status);

// v0.34.0
```

## Get transaction values

| Method | Type | Requirement |
| - | - | - |
| `getFileId()` | FileId | Optional |
| `getKey()` | Key | Optional |
| `setContents()` | ByteString | Optional |
| `getExpirationTime()` | Instant | Optional |
| `getFileMemo()` | String | Optional |

```java Java theme={null}
//Create the transaction
FileUpdateTransaction transaction = new FileUpdateTransaction()
    .setFileId(fileId)
    .setKeys(newKey);

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

//v2.0.0
```

```java JavaScript theme={null}
//Create the transaction
const transaction = new FileUpdateTransaction()
    .setFileId(newFileId);

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

```java Go theme={null}
//Create the transaction
transaction := hedera.NewFileUpdateTransaction().
      SetFileID(fileId).
        SetKeys(newKey)

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

//v2.0.0
```

```rust Rust theme={null}
// Create the transaction
let transaction = FileUpdateTransaction::new()
    .file_id(file_id)
    .keys([new_key]);

// Get the key
let key = transaction.get_key();

// v0.34.0
```
