-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimmutable-token.js
More file actions
104 lines (92 loc) · 3.15 KB
/
immutable-token.js
File metadata and controls
104 lines (92 loc) · 3.15 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
console.clear();
require("dotenv").config();
const {
AccountId,
PrivateKey,
Client,
TokenCreateTransaction,
TokenType,
Hbar,
TokenSupplyType,
AccountCreateTransaction
} = require("@hashgraph/sdk");
// Configure accounts and client, and generate needed keys
const operatorId = AccountId.fromString(process.env.OPERATOR_ID);
const operatorKey = PrivateKey.fromString(process.env.OPERATOR_PVKEY);
const client = Client.forTestnet().setOperator(operatorId, operatorKey);
client.setDefaultMaxTransactionFee(new Hbar(100));
const treasuryKey = PrivateKey.generateED25519();
async function main() {
// Create accounts
const [treasuryAccStatus, treasuryId] = await accountCreatorFcn(treasuryKey, 3);
console.log(`- Created treasury account ${treasuryId} that has a balance of 3ℏ`);
// Create NFT
console.log(`\n- Creating NFT (with only supply key)`);
let nftCreateTx = await new TokenCreateTransaction()
.setTokenName("Fall Collection")
.setTokenSymbol("LEAF")
.setTokenType(TokenType.NonFungibleUnique)
.setDecimals(0)
.setInitialSupply(0)
.setTreasuryAccountId(treasuryId)
.setSupplyType(TokenSupplyType.Finite)
.setMaxSupply(5)
// No admin key, only the required supply key is set
.setSupplyKey(treasuryKey)
.freezeWith(client)
.sign(treasuryKey);
//let nftCreateTxSign = await nftCreateTx.sign(adminKey);
let nftCreateSubmit = await nftCreateTx.execute(client);
let nftCreateRx = await nftCreateSubmit.getReceipt(client);
let tokenId = nftCreateRx.tokenId;
console.log(`- Created NFT with Token ID: ${tokenId}`);
/* Output for token:
{
"admin_key": null,
"auto_renew_account": "0.0.2617920",
"auto_renew_period": 7776000,
"created_timestamp": "1675418666.482710003",
"custom_fees": {
"created_timestamp": "1675418666.482710003",
"fixed_fees": [],
"royalty_fees": []
},
"decimals": "0",
"deleted": false,
"expiry_timestamp": 1683194666482710003,
"fee_schedule_key": null,
"freeze_default": false,
"freeze_key": null,
"initial_supply": "0",
"kyc_key": null,
"max_supply": "5",
"memo": "",
"modified_timestamp": "1675418666.482710003",
"name": "Fall Collection",
"pause_key": null,
"pause_status": "NOT_APPLICABLE",
"supply_key": {
"_type": "ED25519",
"key": "e86357247a5036069236433adb2cdd42c2c3a5d0479b571566a211d4125f7b47"
},
"supply_type": "FINITE",
"symbol": "LEAF",
"token_id": "0.0.3371173",
"total_supply": "0",
"treasury_account_id": "0.0.3371172",
"type": "NON_FUNGIBLE_UNIQUE",
"wipe_key": null
}
*/
client.close();
// ACCOUNT CREATOR FUNCTION ==========================================
async function accountCreatorFcn(pvKey, iBal) {
const response = await new AccountCreateTransaction()
.setInitialBalance(new Hbar(iBal))
.setKey(pvKey.publicKey)
.execute(client);
const receipt = await response.getReceipt(client);
return [receipt.status, receipt.accountId];
}
}
main();