-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtoken-info.mjs
More file actions
50 lines (43 loc) · 1.79 KB
/
Copy pathtoken-info.mjs
File metadata and controls
50 lines (43 loc) · 1.79 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
44
45
46
47
48
49
50
// See https://docs.dash.org/projects/platform/en/stable/docs/tutorials/tokens/retrieve-token-info.html
import { setupDashClient } from '../setupDashClient.mjs';
const { sdk, keyManager } = await setupDashClient();
// TOKEN_CONTRACT_ID comes from token-register.mjs.
const dataContractId = process.env.TOKEN_CONTRACT_ID;
const tokenPosition = 0;
// Default recipient (testnet). Replace or override via RECIPIENT_ID.
const recipientId =
process.env.RECIPIENT_ID || '7XcruVSsGQVSgTcmPewaE4tXLutnW1F6PXxwMbo8GYQC';
try {
if (!dataContractId) {
throw new Error(
'Set TOKEN_CONTRACT_ID in .env from token-register.mjs output.',
);
}
const tokenId = await sdk.tokens.calculateId(dataContractId, tokenPosition);
const contractInfo = await sdk.tokens.contractInfo(tokenId);
const totalSupply = await sdk.tokens.totalSupply(tokenId);
const statuses = await sdk.tokens.statuses([tokenId]);
const identityBalances = await sdk.tokens.identityBalances(
keyManager.identityId,
[tokenId],
);
const recipientBalances = await sdk.tokens.identityBalances(recipientId, [
tokenId,
]);
// A token only has a status record once one is published on-chain (e.g. via
// an emergency pause), so the Map is empty for a freshly registered token.
const status = statuses.get(tokenId);
console.log('Token ID:', tokenId);
console.log('Token contract info:\n', contractInfo?.toJSON());
console.log(
'Token status:',
status ? status.isPaused : '(no status published)',
);
console.log('Total token supply:', totalSupply?.totalSupply ?? 0n);
console.log(`Identity token balance: ${identityBalances.get(tokenId) ?? 0n}`);
console.log(
`Recipient token balance: ${recipientBalances.get(tokenId) ?? 0n}`,
);
} catch (e) {
console.error('Something went wrong:\n', e.message);
}