-
Notifications
You must be signed in to change notification settings - Fork 2
/
get-cluster-balance.js
40 lines (32 loc) · 1.14 KB
/
get-cluster-balance.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
require('dotenv').config()
const { getClient } = require('@phala/sdk')
const BN = require('bn.js')
const argv = require('arg')({
'--ws': String,
})
async function main() {
const endpoint = argv['--ws'] || process.env.ENDPOINT
if (!endpoint) {
console.log('Please create your own .env file with `ENDPOINT` and `POLKADOT_ACCOUNT`.')
return process.exit(1)
}
if (!argv['_'].length) {
console.log('Usage: node get-cluster-balance.js <address>')
return process.exit(1)
}
const address = argv['_'][0]
// Initialization
console.log('Connecting to', endpoint, '...')
const client = await getClient({ transport: endpoint })
console.log('Connected.')
const accountInfo = await client.api.query.system.account(address)
const free = accountInfo.data.free.div(new BN(1e10)) / 100
console.log(`Account ${address} has ${free} PHA.`)
const balance = await client.getClusterBalance(address)
console.log('Cluster Balance total:', balance.total.toPrimitive() / 1e12)
console.log('Cluster Balance free:', balance.free.toPrimitive() / 1e12)
}
main().then(() => process.exit(0)).catch(err => {
console.error(err)
process.exit(1)
})