-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtoken-mint.mjs
More file actions
39 lines (32 loc) · 1.24 KB
/
Copy pathtoken-mint.mjs
File metadata and controls
39 lines (32 loc) · 1.24 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
// See https://docs.dash.org/projects/platform/en/stable/docs/tutorials/tokens/mint-tokens.html
import { setupDashClient } from '../setupDashClient.mjs';
const { sdk, keyManager } = await setupDashClient();
const { identity, identityKey, signer } = await keyManager.getAuth();
// TOKEN_CONTRACT_ID comes from token-register.mjs.
const dataContractId = process.env.TOKEN_CONTRACT_ID;
const tokenPosition = 0;
const amount = 10n; // Token amounts are bigint values
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);
await sdk.tokens.mint({
dataContractId,
tokenPosition,
amount,
identityId: identity.id.toString(),
identityKey,
signer,
});
const balances = await sdk.tokens.identityBalances(identity.id, [tokenId]);
const totalSupply = await sdk.tokens.totalSupply(tokenId);
console.log(`Minted ${amount} tokens`);
console.log('Token ID:', tokenId);
console.log(`Identity token balance: ${balances.get(tokenId) ?? 0n}`);
console.log('Total token supply:', totalSupply?.totalSupply ?? 0n);
} catch (e) {
console.error('Something went wrong:\n', e.message);
}