-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetTokenAccountBalance.js
37 lines (26 loc) · 1.1 KB
/
getTokenAccountBalance.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
const { Client, AccountId, PrivateKey, AccountBalanceQuery, Hbar} = require("@hashgraph/sdk");
const prompt = require('prompt-sync')();
require("dotenv").config();
async function main() {
// Load hedera credentials
// If you want to go on mainnet delete TESTNET_
const myAccountId = AccountId.fromString(process.env.TESTNET_MY_ACCOUNT_ID);
const myPrivateKey = PrivateKey.fromString(process.env.TESTNET_MY_PRIVATE_KEY);
// Credential error handler
if (myAccountId == null ||
myPrivateKey == null ) {
throw new Error("Environment variables myAccountId and myPrivateKey must be present");
}
// Build the client/operator
// If you wanna go mainnet use forMainnet() instead of forTestnet()
const client = Client.forTestnet();
client.setOperator(myAccountId, myPrivateKey);
const accountId = prompt('CUENTA A CONSULTAR: ');
// Instance of the query
const query = new AccountBalanceQuery()
.setAccountId(accountId);
// Execute query and get response
const tokenBalance = await query.execute(client);
console.log("Saldo de tokens: " +tokenBalance.tokens.toString());
}
main();