-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnftCollection.js
48 lines (39 loc) · 1.44 KB
/
nftCollection.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
// Step 1: Creation of a variable to hold our NFTs
let nfts = [];
let usedIds = new Set(); // Create a Set to store used IDs
// Step 2: Create a function to generate a random ID
function generateRandomId() {
let id;
do {
id = Math.floor(Math.random() * 1000) + 1; // Generate a random ID between 1 and 1000
} while (usedIds.has(id)); // Repeat if the ID is already used
usedIds.add(id); // Add the new unique ID to the Set
return id;
}
// Step 2: Creating a function to mint NFTs
function mintNFT(title, author, publicationYear, genre) {
let nft = {
id: generateRandomId(), // Assign a unique random ID
title: title,
author: author,
publicationYear: publicationYear,
genre: genre
};
// Adding NFT object to the array
nfts.push(nft);
}
// Step 3: Creating a function to list all NFTs in a tabular format
function listNFTs() {
console.table(nfts);
}
// Step 4: Creating a function to get the total supply of NFTs
function getTotalSupply() {
return nfts.length;
}
// Minting some NFTs with Indian book details
mintNFT("The God of Small Things", "Arundhati Roy", 1997, "Fiction");
mintNFT("Midnight's Children", "Salman Rushdie", 1981, "Historical Fiction");
mintNFT("The White Tiger", "Aravind Adiga", 2008, "Fiction");
listNFTs();
// Printing the total supply of NFTs
console.log(`Total NFTs minted: ${getTotalSupply()}`);