-
Notifications
You must be signed in to change notification settings - Fork 1
/
4-fractionalize-wine.js
87 lines (71 loc) · 2.39 KB
/
4-fractionalize-wine.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
82
83
84
85
86
87
import {
TokenCreateTransaction,
TokenMintTransaction,
TokenType,
TokenSupplyType,
PrivateKey,
Client,
AccountId,
Hbar,
} 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();
const cid = new TextEncoder().encode(
"ipfs://QmVtvHUCbVdRpmg5YFtfaYuX5LtYgWhAGpoBG3tDTpyC58"
);
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(10)
.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 nftCreateTxReceipt = await nftCreateTxResponse.getReceipt(client);
console.log(
`Status of NFT create transaction: ${nftCreateTxReceipt.status.toString()}`
);
// Get token id
const tokenId = nftCreateTxReceipt.tokenId;
console.log(`Token id: ${tokenId.toString()}`);
// Mint token
const nftMintTx = new TokenMintTransaction()
.setMetadata([cid, cid])
.setMaxTransactionFee(new Hbar(20))
.setTokenId(tokenId)
.freezeWith(client);
const nftMintTxResponse = await (
await nftMintTx.sign(supplyKey)
).execute(client);
const nftMintTxReceipt = await nftMintTxResponse.getReceipt(client);
console.log(
`Status of NFT mint transction: ${nftMintTxReceipt.status.toString()}`
);
// go to hashscan and show the minted serial -> there's no metadata or image
} catch (error) {
console.log(error);
}
client.close();
}
main();