-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviewfilecontent.js
More file actions
37 lines (30 loc) · 1.16 KB
/
Copy pathviewfilecontent.js
File metadata and controls
37 lines (30 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const { Client, FileId, FileContentsQuery } = require("@hashgraph/sdk");
require('dotenv').config();
const fs = require('fs');
async function viewFile() {
// Initialize the Hedera client
const client = Client.forTestnet();
client.setOperator(process.env.MY_ACCOUNT_ID, process.env.MY_PRIVATE_KEY);
// Read the fileId from fileId.txt
fs.readFile('fileId.txt', 'utf8', async (err, fileIdStr) => {
if (err) {
console.error("Error reading fileId.txt:", err);
return;
}
try {
// Convert the fileId string to a FileId object
const fileId = FileId.fromString(fileIdStr.trim());
// Create a query to get the file contents
const fileContentsQuery = new FileContentsQuery()
.setFileId(fileId);
// Execute the query
const fileContents = await fileContentsQuery.execute(client);
// Log the file contents
console.log("File Contents:", fileContents.toString());
} catch (error) {
console.error("Error retrieving file contents:", error);
}
});
}
// Call the function
viewFile();