-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmintAdditionalFungibleTokens.mjs
86 lines (66 loc) · 2.16 KB
/
mintAdditionalFungibleTokens.mjs
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import dotenv from 'dotenv';
dotenv.config();
import { AccountId, PrivateKey, Client, AccountBalanceQuery, TokenMintTransaction, TokenId } from '@hashgraph/sdk';
// Configure accounts and client, and generate needed keys
const myAcctID = AccountId.fromString(process.env.MY_ACCOUNT_ID);
const myAcctPK = PrivateKey.fromString(process.env.MY_PRIVATE_KEY);
const tokenId = TokenId.fromString(process.env.FT_TOKEN_ID);
const supplyKey = PrivateKey.fromString(process.env.FT_SUPPLY_KEY);
function getArg(arg) {
const customIndex = process.argv.indexOf(`-${arg}`);
let customValue;
if (customIndex > -1) {
// Retrieve the value after --custom
customValue = process.argv[customIndex + 1];
}
return customValue;
}
function getArgFlag(arg) {
const customIndex = process.argv.indexOf(`-${arg}`);
if (customIndex > -1) {
return true;
}
return false;
}
async function main() {
if (getArgFlag('h')) {
console.log('Usage: node mintAdditionalFungibleTokens.mjs [-mainnet] -supply XXX');
return;
}
let client;
if (getArgFlag('mainnet')) {
console.log('using mainnet');
client = Client.forMainnet();
}
else {
console.log('Using testnet');
client = Client.forTestnet();
}
let supply = 0;
if (getArgFlag('supply')) {
supply = Number(getArg('supply'));
if (!Number.isInteger(supply)) {
console.log('-supply need an integer argument..exiting');
return;
}
}
else {
console.log('Must specify the supply to mint');
return;
}
client.setOperator(myAcctID, myAcctPK);
// CREATE FUNGIBLE TOKEN (STABLECOIN)
const tokenMintTx = new TokenMintTransaction()
.setTokenId(tokenId)
.setAmount(supply)
.freezeWith(client);
console.log(`Creating supply of ${supply} for ${tokenId}`);
const tokenMintSign = await tokenMintTx.sign(supplyKey);
const tokenMintSubmit = await tokenMintSign.execute(client);
const tokenMintRx = await tokenMintSubmit.getReceipt(client);
console.log('result:', tokenMintRx.status.toString());
// BALANCE CHECK
const balanceCheckTx = await new AccountBalanceQuery().setAccountId(myAcctID).execute(client);
console.log(`- Treasury balance: ${balanceCheckTx.tokens._map.get(tokenId.toString())} units of token ID ${tokenId}`);
}
main();