-
Notifications
You must be signed in to change notification settings - Fork 1
/
1-wine-bottle.js
64 lines (52 loc) · 1.87 KB
/
1-wine-bottle.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
import {
TokenCreateTransaction,
TokenType,
TokenSupplyType,
PrivateKey,
Client,
AccountId,
} from "@hashgraph/sdk";
import dotenv from "dotenv";
dotenv.config();
async function main() {
const operatorId = AccountId.fromString(process.env.OPERATOR_ID);
const operatorKey = PrivateKey.fromString(process.env.OPERATOR_PVKEY);
// If we weren't able to grab it, we should throw a new error
if (operatorId == null || operatorKey == null) {
throw new Error(
"Environment variables operatorId and operatorKey must be present"
);
}
const client = Client.forTestnet().setOperator(operatorId, operatorKey);
// Generate a supply key
const supplyKey = PrivateKey.generateED25519();
try {
// Create a non fungible token
let nftCreateTx = new TokenCreateTransaction()
.setTokenName("Petrus")
.setTokenSymbol("P1996")
.setTokenType(TokenType.NonFungibleUnique)
.setDecimals(0)
.setInitialSupply(0)
.setSupplyType(TokenSupplyType.Finite)
.setMaxSupply(1)
.setTreasuryAccountId(operatorId)
.setSupplyKey(supplyKey)
.freezeWith(client);
// Sign and execute create token transaction
const nftCreateTxSigned = await nftCreateTx.sign(operatorKey);
const nftCreateTxResponse = await nftCreateTxSigned.execute(client);
// Get receipt for create token transaction
const tokenCreateTxReceipt = await nftCreateTxResponse.getReceipt(client);
console.log(
`Status of token create transaction: ${tokenCreateTxReceipt.status.toString()}`,
);
// Get token id
const tokenId = tokenCreateTxReceipt.tokenId;
console.log(`Token id: ${tokenId.toString()}`);
} catch (error) {
console.log(error);
}
client.close();
}
main();