Hedera
Search…
Append to a file
A transaction that appends new file content to the end of an existing file. The contents of the file can be viewed by submitting a FileContentsQuery request.
Transaction Signing Requirements
    The key on the file is required to sign the transaction if different than the client operator account key
Constructor
Description
FileAppendTransaction()
Initializes the FileAppendTransaction object
1
new FileAppendTransaction()
Copied!
The default max transaction fee (1 hbar) is not enough to create a file. Use setMaxTransactionFee()to change the default max transaction fee from 1 hbar to 2 hbars

Methods

V2
V1
Method
Type
Description
Requirement
setFileId(<fileId>)
FileId
The ID of the file to append
Required
setContents(<text>)
String
The content in String format
Optional
setContents(<content>)
byte [ ]
The content in byte format
Optional
Java
1
//Create the transaction
2
FileAppendTransaction transaction = new FileAppendTransaction()
3
.setFileId(newFileId)
4
.setContents("The appended contents");
5
6
//Change the default max transaction fee to 2 hbars
7
FileCreateTransaction modifyMaxTransactionFee = transaction.setMaxTransactionFee(new Hbar(2));
8
9
//Prepare transaction for signing, sign with the key on the file, sign with the client operator key and submit to a Hedera network
10
TransactionResponse txResponse = modifyMaxTransactionFee.freezeWith(client).sign(key).execute(client);
11
12
//Request the receipt
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 FileAppendTransaction()
3
.setFileId(newFileId)
4
.setContents("The appended 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 key and submit to a Hedera network
12
const txResponse = await signTx.execute(client);
13
14
//Request the receipt
15
const receipt = await txResponse.getReceipt(client);
16
17
//Get the transaction consensus status
18
const transactionStatus = receipt.status;
19
20
console.log("The transaction consensus status is " +transactionStatus);
21
22
//v2.0.5
Copied!
Go
1
//Create the transaction
2
transaction2 := hedera.NewFileAppendTransaction().
3
SetFileID(newFileId).
4
SetContents([]byte("The appended contents"))
5
6
//Change the default max transaction fee to 2 hbars
7
modifyMaxTransactionFee := transaction.SetMaxTransactionFee(hedera.HbarFrom(2, hedera.HbarUnits.Hbar))
8
9
//Prepare 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
txResponse2 err := freezeTransaction.Sign(fileKey).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 consensus status
28
transactionStatus := receipt.Status
29
30
fmt.Println("The transaction consensus status is ", transactionStatus)
31
32
//v2.0.0
Copied!
Method
Type
Description
Requirement
setFileId(<fileId>)
FileId
The ID of the file to append
Required
setContents(<content>)
byte [ ]
The content in byte format
Optional
setContents(<content>)
String
The content in string format
Optional
Java
1
FileAppendTransaction transaction = new FileAppendTransaction()
2
.setFileId(newFileId)
3
.setContents("The appended contents")
4
.setMaxTransactionFee(new Hbar(2));
5
6
//Prepare transaction for signing, sign with the key on the file, sign with the client operator key and submit to a Hedera network
7
TransactionId txId = transaction.build(client).sign(key).execute(client);
8
9
//Request the receipt
10
TransactionReceipt receipt1 = txId.getReceipt(client);
11
12
//Get the transaction consensus status
13
Status transactionStatus = receipt.status;
14
15
System.out.println("The transaction consensus status is " +transactionStatus)
Copied!
JavaScript
1
const transaction = new FileAppendTransaction()
2
.setFileId(newFileId)
3
.setContents("The appended contents")
4
.setMaxTransactionFee(new Hbar(2));
5
6
//Prepare transaction for signing, sign with the key on the file, sign with the client operator key and submit to a Hedera network
7
const txId = await transaction.build(client).sign(key).execute(client);
8
9
//Request the receipt
10
const receipt = await txId.getReceipt(client);
11
12
//Get the transaction consensus status
13
Status transactionStatus = receipt.status;
14
15
console.log("The transaction consensus status is " +transactionStatus)
Copied!

Get transaction values

V2
Method
Type
Description
Requirement
getFileId()
FileId
The file ID in the transaction
Optional
getContents()
String
The content in the transaction
Optional
Java
1
//Create the transaction
2
FileAppendTransaction transaction = new FileAppendTransaction()
3
.setFileId(newFileId)
4
.setContents("The appended contents");
5
6
//Get the contents
7
ByteString getContents = transaction.getContents();
8
9
//v2.0.0
Copied!
JavaScript
1
//Create the transaction
2
const transaction = new FileAppendTransaction()
3
.setFileId(newFileId)
4
.setContents("The appended contents");
5
6
//Get the contents
7
const getContents = transaction.getContents();
Copied!
Go
1
//Create the transaction
2
transaction2 := hedera.NewFileAppendTransaction().
3
SetFileID(newFileId).
4
SetContents([]byte("The appended contents"))
5
6
//Get the contents
7
getContents2 := transaction2.GetContents()
8
9
//v2.0.0
Copied!
Last modified 6d ago