-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbalances.js
More file actions
43 lines (37 loc) · 1.15 KB
/
balances.js
File metadata and controls
43 lines (37 loc) · 1.15 KB
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
import StellarSdk from "@stellar/stellar-sdk";
import config from "./config.json" assert { type: "json" };
const {
accounts: { issuer, distributor, buyer },
network: { serverUrl }
} = config;
// Access the correct Server class
const server = new StellarSdk.Horizon.Server(serverUrl);
const displayTemplate = ({ name, accountId, balances }) => {
console.log(
`\u001b[33m${name}\u001b[0m \u001b[37;2m${accountId.substring(
0,
9
)}${Array.from(new Array(15 - name.length))
.map(() => "⋅")
.join("")}\u001b[0m${balances}`
);
};
const checkAccounts = async () => {
const stellarAccounts = await Promise.all(
[issuer, distributor, buyer].map(async ({ name, publicKey }) => {
const account = await server.loadAccount(publicKey);
return {
name,
accountId: publicKey,
balances: account.balances.map(
({ balance, asset_type, asset_code }) =>
`${balance} ${asset_type === "native" ? "Test-π" : asset_code}`
)
};
})
);
stellarAccounts.forEach(displayTemplate);
};
checkAccounts().catch(e => {
console.error("Error:", e.response?.data || e);
});