forked from hashgraph/hedera-sdk-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mint-big-number-of-units-of-token.js
68 lines (56 loc) · 1.9 KB
/
mint-big-number-of-units-of-token.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
67
68
import {
AccountId,
Client,
PrivateKey,
TokenCreateTransaction,
TokenType,
TokenMintTransaction,
TokenInfoQuery,
Long,
Status,
} from "@hashgraph/sdk";
import dotenv from "dotenv";
dotenv.config();
async function main() {
const operatorKey = PrivateKey.fromStringECDSA(process.env.OPERATOR_KEY);
const operatorId = AccountId.fromString(process.env.OPERATOR_ID);
const client = Client.forName(process.env.HEDERA_NETWORK).setOperator(
operatorId,
operatorKey,
);
let tokenCreate = await new TokenCreateTransaction()
.setTokenName("Token")
.setTokenSymbol("T")
.setTokenType(TokenType.FungibleCommon)
.setDecimals(8)
.setTreasuryAccountId(operatorId)
.setSupplyKey(operatorKey)
.execute(client);
let tokenCreateReceipt = await tokenCreate.getReceipt(client);
const tokenId = tokenCreateReceipt.tokenId;
console.log(`TokenId is ${tokenId.toString()}.`);
// If the number of tokens that should be minted is bigger
// than Number.MAX_SAFE_INTEGER it should be passed as a Long number
const amount = Long.fromValue("25817858423044461");
console.log(`Token balance will be set to ${amount.toString()}.`);
let tokenMint = await new TokenMintTransaction()
.setTokenId(tokenId)
.setAmount(amount)
.execute(client);
const tokenMintReciept = await tokenMint.getReceipt(client);
if (tokenMintReciept.status === Status.Success) {
console.log("Token has been minted!");
} else {
console.error("Token mint transaction failed.");
}
let tokenInfo = await new TokenInfoQuery()
.setTokenId(tokenId)
.execute(client);
if (tokenInfo) {
console.log(`Token Balance = ${tokenInfo.totalSupply.toString()}`);
} else {
console.error("Token query failed.");
}
client.close();
}
void main();