-
Notifications
You must be signed in to change notification settings - Fork 146
/
Copy pathget-exchangerates.js
62 lines (52 loc) · 1.61 KB
/
get-exchangerates.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import {
Wallet,
LocalProvider,
FileContentsQuery,
ExchangeRates,
} from "@hashgraph/sdk";
import dotenv from "dotenv";
dotenv.config();
async function main() {
if (
process.env.OPERATOR_ID == null ||
process.env.OPERATOR_KEY == null ||
process.env.HEDERA_NETWORK == null
) {
throw new Error(
"Environment variables OPERATOR_ID, HEDERA_NETWORK, and OPERATOR_KEY are required.",
);
}
const provider = new LocalProvider();
const wallet = new Wallet(
process.env.OPERATOR_ID,
process.env.OPERATOR_KEY,
provider,
);
let resp;
try {
resp = await new FileContentsQuery()
.setFileId("0.0.112")
.executeWithSigner(wallet);
} catch (error) {
console.error(error);
}
const exchangeRates = ExchangeRates.fromBytes(resp);
console.log(`Current numerator ${exchangeRates.currentRate.cents}`);
console.log(`Current denominator ${exchangeRates.currentRate.hbars}`);
console.log(
`Current expiration time ${exchangeRates.currentRate.expirationTime.toString()}`,
);
console.log(
`Current Exchange Rate ${exchangeRates.currentRate.exchangeRateInCents}`,
);
console.log(`Next numerator ${exchangeRates.nextRate.cents}`);
console.log(`Next denominator ${exchangeRates.nextRate.hbars}`);
console.log(
`Next expiration time ${exchangeRates.nextRate.expirationTime.toString()}`,
);
console.log(
`Next Exchange Rate ${exchangeRates.nextRate.exchangeRateInCents}`,
);
provider.close();
}
void main();