forked from cisc0f/hedera
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
71 lines (54 loc) · 1.96 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
62
63
64
65
66
67
68
69
70
71
const {
Client,
TokenCreateTransaction,
PrivateKey,
AccountId,
AccountCreateTransaction,
Hbar,
TokenType,
TokenSupplyType
} = 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 NFT
const nftCreate = await new TokenCreateTransaction()
.setTokenName("Fall Collection")
.setTokenSymbol("LEAF")
.setTokenType(TokenType.NonFungibleUnique)
.setDecimals(0)
.setTokenMemo("Just a memo")
.setInitialSupply(0)
.setTreasuryAccountId(treasuryId)
.setSupplyType(TokenSupplyType.Finite)
.setSupplyKey(treasuryKey)
.setMaxSupply(250)
.setAutoRenewAccountId(treasuryId)
.setAutoRenewPeriod(7000000)
.freezeWith(client);
//Sign the transaction with the treasury key
const nftCreateTxSign = await nftCreate.sign(treasuryKey);
//Submit the transaction to a Hedera network
const nftCreateSubmit = await nftCreateTxSign.execute(client);
//Get the transaction receipt
const nftCreateRx = await nftCreateSubmit.getReceipt(client);
//Get the token ID
const tokenId = nftCreateRx.tokenId;
//Log the token ID
console.log(`Created NFT with ID: ${tokenId} \n`);
}
main();