forked from junobuild/juno
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathledger.balance.mjs
36 lines (26 loc) · 1.07 KB
/
ledger.balance.mjs
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
import { IcrcLedgerCanister } from '@dfinity/ledger-icrc';
import { icAgent, localAgent } from './actor.mjs';
import { getIdentity } from './console.config.utils.mjs';
import { CONSOLE_ID, LEDGER_ID } from './constants.mjs';
import { accountIdentifier } from './ledger.utils.mjs';
import { targetMainnet } from './utils.mjs';
const getBalance = async (mainnet, console_) => {
const agent = await (mainnet ? icAgent : localAgent)();
const { balance } = IcrcLedgerCanister.create({
agent,
canisterId: LEDGER_ID
});
const owner = console_ ? CONSOLE_ID : getIdentity(mainnet).getPrincipal();
const e8sBalance = await balance({
owner,
certified: false
});
const E8S_PER_ICP = 100_000_000n;
const formatE8sICP = (balance) => `${balance / E8S_PER_ICP} ICP`;
console.log(formatE8sICP(e8sBalance), '|', e8sBalance);
const identifier = await accountIdentifier(mainnet, owner);
console.log(identifier.toHex());
};
const mainnet = targetMainnet();
const console_ = process.argv.find((arg) => arg.indexOf(`--console`) > -1) !== undefined;
await getBalance(mainnet, console_);