-
Notifications
You must be signed in to change notification settings - Fork 12
/
index.js
61 lines (44 loc) · 1.89 KB
/
index.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
const {
Client,
TokenCreateTransaction,
PrivateKey, AccountId, AccountCreateTransaction, Hbar
} = require('@hashgraph/sdk');
require('dotenv').config({path: __dirname + '/../../.env'});
// Get operator from .env file
const operatorKey = PrivateKey.fromString(process.env.PRIVATE_KEY);
const operatorId = AccountId.fromString(process.env.ACCOUNT_ID);
const client = Client.forTestnet().setOperator(operatorId, operatorKey);
// Account creation function
async function accountCreator(pvKey, iBal) {
const response = await new AccountCreateTransaction()
.setInitialBalance(new Hbar(iBal))
.setKey(pvKey.publicKey)
.execute(client);
const receipt = await response.getReceipt(client);
return receipt.accountId;
}
const main = async () => {
const treasuryKey = PrivateKey.generateED25519();
const treasuryId = await accountCreator(treasuryKey, 10);
//Create the transaction and freeze for manual signing
const transaction = await new TokenCreateTransaction()
.setTokenName("USD Bar")
.setTokenSymbol("USDB")
.setTreasuryAccountId(treasuryId)
.setInitialSupply(10000)
.setDecimals(2)
.setAutoRenewAccountId(treasuryId)
.setAutoRenewPeriod(7000000)
.setMaxTransactionFee(new Hbar(30)) //Change the default max transaction fee
.freezeWith(client);
//Sign the transaction with the token adminKey and the token treasury account private key
const signTx = await transaction.sign(treasuryKey);
//Sign the transaction with the client operator private key and submit to a Hedera network
const txResponse = await signTx.execute(client);
//Get the receipt of the transaction
const receipt = await txResponse.getReceipt(client);
//Get the token ID from the receipt
const tokenId = receipt.tokenId;
console.log("The new token ID is " + tokenId);
}
main();