use of com.hedera.hashgraph.sdk.NodeAddressBook in project hedera-sdk-java by hashgraph.
the class GetAddressBookExample method main.
public static void main(String[] args) throws PrecheckStatusException, IOException, TimeoutException {
Client client = Client.forName(HEDERA_NETWORK);
// Defaults the operator account ID and key such that all generated transactions will be paid for
// by this account and be signed by this key
client.setOperator(OPERATOR_ID, OPERATOR_KEY);
FileContentsQuery fileQuery = new FileContentsQuery().setFileId(FileId.ADDRESS_BOOK);
Hbar cost = fileQuery.getCost(client);
System.out.println("file contents cost: " + cost);
fileQuery.setMaxQueryPayment(new Hbar(1));
ByteString contents = fileQuery.execute(client);
Files.deleteIfExists(FileSystems.getDefault().getPath("address-book.proto.bin"));
Files.copy(new ByteArrayInputStream(contents.toByteArray()), FileSystems.getDefault().getPath("address-book.proto.bin"));
// NEW (Feb 25 2022): you can now fetch the address book for free from a mirror node with AddressBookQuery
NodeAddressBook addressBook = new AddressBookQuery().setFileId(FileId.ADDRESS_BOOK).execute(client);
System.out.println(addressBook);
}
Aggregations