forked from hiero-ledger/hiero-sdk-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-address-book.js
33 lines (22 loc) · 870 Bytes
/
get-address-book.js
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
import { Client, FileId, AddressBookQuery } from "@hashgraph/sdk";
import fs from "node:fs/promises";
import dotenv from "dotenv";
dotenv.config();
async function main() {
if (process.env.HEDERA_NETWORK == null) {
throw new Error("Environment variable HEDERA_NETWORK is required.");
}
const client = Client.forName(process.env.HEDERA_NETWORK);
if (process.env.HEDERA_NETWORK.toLowerCase() === "mainnet") {
client
.setMirrorNetwork(["mainnet-public.mirrornode.hedera.com:443"])
.setTransportSecurity(true);
}
const addressBook = await new AddressBookQuery()
.setFileId(FileId.ADDRESS_BOOK)
.execute(client);
console.log(JSON.stringify(addressBook.toJSON(), null, 2));
await fs.writeFile("address-book.proto.bin", addressBook.toBytes());
client.close();
}
void main();