-
Notifications
You must be signed in to change notification settings - Fork 12
/
utils.js
40 lines (34 loc) · 1.24 KB
/
utils.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
const {
TokenCreateTransaction,
Hbar,
AccountCreateTransaction
} = require("@hashgraph/sdk");
async function accountCreator(pvKey, iBal, client) {
const response = await new AccountCreateTransaction()
.setInitialBalance(new Hbar(iBal))
.setKey(pvKey.publicKey)
.execute(client);
const receipt = await response.getReceipt(client);
return receipt.accountId;
}
async function tokenCreator(adminKey, treasuryId, treasuryKey, client) {
//Create the transaction and freeze for manual signing
const createToken = await new TokenCreateTransaction()
.setTokenName("USD Bar")
.setTokenSymbol("USDB")
.setTreasuryAccountId(treasuryId)
.setInitialSupply(10000)
.setDecimals(2)
.setAdminKey(adminKey.publicKey)
.setMaxTransactionFee(new Hbar(20)) //Change the default max transaction fee
.freezeWith(client);
const createTokenTx = await (await createToken.sign(adminKey)).sign(treasuryKey);
const createTokenRx = await createTokenTx.execute(client);
const createTokenReceipt = await createTokenRx.getReceipt(client);
const tokenId = createTokenReceipt.tokenId;
return tokenId;
}
module.exports = {
accountCreator,
tokenCreator
}