-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateToken.js
81 lines (63 loc) · 2.81 KB
/
createToken.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
69
70
71
72
73
74
75
76
77
78
79
80
81
const { Client, TokenCreateTransaction, Hbar, AccountId, PrivateKey} = require("@hashgraph/sdk");
const prompt = require('prompt-sync')();
require("dotenv").config();
async function main() {
// Load hedera credentials
// If you want to go on mainnet delete TESTNET_
const myAccountId = AccountId.fromString(process.env.TESTNET_MY_ACCOUNT_ID);
const myPrivateKey = PrivateKey.fromString(process.env.TESTNET_MY_PRIVATE_KEY);
// Credential error handler
if (myAccountId == null ||
myPrivateKey == null ) {
throw new Error("Environment variables myAccountId and myPrivateKey must be present");
}
// Build the client/operator
// If you wanna go mainnet use forMainnet() instead of forTestnet()
const client = Client.forTestnet();
client.setOperator(myAccountId, myPrivateKey);
// Create transaction and freeze for signing
const tempTokenName = prompt('Ingrese el nombre de token: ');
const tempTokenSymbol = prompt('Ingrese el simbolo de token: ');
const tempSupply = prompt('Ingrese el Supply: ');
const tempDecimals = prompt('Ingrese cantidad de decimales: ')
// const tempMemo = prompt('Ingrese mensaje (memo) publico: ')
const adminKey = await PrivateKey.generate();
console.log(`Admin Key: ${adminKey}`)
console.log(`Admin Public Key: ${adminKey.publicKey}`)
const treasuryKey = await PrivateKey.generate();
console.log(`Treasury Key: ${treasuryKey}`)
console.log(`Treasury Public Key: ${treasuryKey.publicKey}`)
const supplyKey = await PrivateKey.generate();
console.log(`Supply Key: ${supplyKey}`)
console.log(`Supply Public Key: ${supplyKey.publicKey}`)
// const kycKey = await PrivateKey.generate();
// console.log(`KYC Key: ${kycKey}`)
// console.log(`KYC Public Key: ${kycKey.publicKey}`)
const freezeKey = await PrivateKey.generate();
console.log(`Freeze Key: ${freezeKey}`)
console.log(`Freeze Public Key: ${freezeKey.publicKey}`)
const wipeKey = await PrivateKey.generate();
console.log(`Wipe Key: ${wipeKey}`)
console.log(`Wipe Public Key: ${wipeKey.publicKey}`)
const transaction = await new TokenCreateTransaction()
.setTokenName(tempTokenName)
.setTokenSymbol(tempTokenSymbol)
.setTreasuryAccountId(myAccountId)
.setInitialSupply(tempSupply)
.setDecimals(tempDecimals)
.setSupplyKey(supplyKey.publicKey)
.setAdminKey(adminKey.publicKey)
// .setKycKey(kycKey.publicKey)
.setFreezeKey(freezeKey.publicKey)
.setWipeKey(wipeKey.publicKey)
// .setTokenMemo(tempMemo)
.setMaxTransactionFee(new Hbar(5))
.freezeWith(client);
// Sign transaction and get tokenId as response
const signTx = await (await transaction.sign(adminKey)).sign(treasuryKey);
const txResponse = await signTx.execute(client);
const receipt = await txResponse.getReceipt(client);
const tokenId = receipt.tokenId;
console.log("Tu token ID es: " + tokenId);
}
main()