use of com.hedera.hashgraph.sdk.ExchangeRates in project hedera-sdk-java by hashgraph.
the class GetExchangeRatesExample method main.
public static void main(String[] args) throws ReceiptStatusException, TimeoutException, PrecheckStatusException, InvalidProtocolBufferException {
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);
// Get contents of file 0.0.112
ByteString fileContentsByteString = new FileContentsQuery().setFileId(FileId.fromString("0.0.112")).execute(client);
byte[] fileContents = fileContentsByteString.toByteArray();
ExchangeRates exchangeRateSet = ExchangeRates.fromBytes(fileContents);
// Prints query results to console
System.out.println("Current numerator: " + exchangeRateSet.currentRate.cents);
System.out.println("Current denominator: " + exchangeRateSet.currentRate.hbars);
System.out.println("Current expiration time: " + exchangeRateSet.currentRate.expirationTime.toString());
System.out.println("Current Exchange Rate: " + exchangeRateSet.currentRate.exchangeRateInCents);
System.out.println("Next numerator: " + exchangeRateSet.nextRate.cents);
System.out.println("Next denominator: " + exchangeRateSet.nextRate.hbars);
System.out.println("Next expiration time: " + exchangeRateSet.nextRate.expirationTime.toString());
System.out.println("Next Exchange Rate: " + exchangeRateSet.nextRate.exchangeRateInCents);
}
Aggregations