-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathquery.js
66 lines (56 loc) · 2.44 KB
/
query.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
63
64
65
66
// Load Avalanche client helper
const client = require("./client")
async function main() {
console.log("========== Info ==========")
await queryInfo(client.Info())
console.log("========== Platform Chain Info ==========")
await queryPChain(client.PChain())
console.log("========== Exchange Chain Info ==========")
await queryXChain(client.XChain())
}
async function queryInfo(info) {
// 1.Query info
console.log("- X:", await info.getBlockchainID("X"), await info.isBootstrapped("X"))
console.log("- P:", await info.getBlockchainID("P"), await info.isBootstrapped("P"))
console.log("- C:", await info.getBlockchainID("C"), await info.isBootstrapped("C"))
console.log("- Fees:", await info.getTxFee())
}
async function queryPChain(pChain) {
// 2. Query P-Chain
// Fetch validator subnets
console.log("Fetching validator subnets...")
const subnets = await pChain.getSubnets()
console.log("Found subnets:", subnets.length)
console.log("Subnet example:", subnets[0])
// Fetch information about Platform chain
console.log("Fetching validators...")
const { validators } = await pChain.getCurrentValidators()
console.log("Found validators:", validators.length)
console.log("Example validator:", validators[0])
// Fetch validator details
const validator = validators[0]
const ownerBalance = await pChain.getBalance(validator.rewardOwner.addresses[0])
console.log("Validator owner balance:", ownerBalance.balance)
// Fetch current height
const height = await pChain.getHeight()
console.log("Current height:", height.toString(10))
// Fetch current minimum staking amount for running a validator
const minStake = await pChain.getMinStake()
console.log("Current min stake:", minStake.minValidatorStake.toString(10))
// Fetch current supply
const supply = await pChain.getCurrentSupply()
console.log("Current supply:", supply.toString(10))
}
async function queryXChain(xChain) {
// 3. Query X-Chain
const fee = await xChain.getDefaultTxFee()
console.log("Default Fee:", fee.toString(10))
const status = await xChain.getTxStatus("2AjbGiRg1KG7FtuJqVEtCzi48n8jpwWdLLYwnBxfFCwMozMLMg")
console.log("Transaction status:", status)
const balances = await xChain.getAllBalances("X-fuji1h4646056wc84fr7jlmmx7t6u3e348ehwzefl5u")
console.log("Balances:", balances)
}
main().catch((err) => {
console.log("We have encountered an error!")
console.error(err)
})