Game of Thrones - NFT
Harshit Singhai
A web app to mint game of thrones NFT in Rinkeby Network.
What is the app about
Users connect their Ethereum wallet, and mint Game of Thrones quote NFT to their wallet so they actually own it. They'll even be able to re-sell the NFT on OpenSea.
Smart Contract
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.4;
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "hardhat/console.sol";
contract ShadowNFT is ERC721URIStorage {
// Using OpenZeppelin to help us keep track of tokenIds.
using Counters for Counters.Counter;
Counters.Counter private _tokenIds;
event NewNFTMinted(address sender, uint256 tokenId);
// We need to pass the name of our NFTs token and it's symbol.
constructor() ERC721("ShadowNFT", "SNFT") {
console.log("This is my NFT Contract. Yeah!!");
}
// A function our user will hit to get their NFT.
function makeAnEpicNFT(string memory metadata) public {
// Get the current tokenId, this starts at 0.
uint256 newItemId = _tokenIds.current();
// Actually mint the NFT to the sender using msg.sender.
_safeMint(msg.sender, newItemId);
// Set the NFTs data
_setTokenURI(newItemId, metadata);
console.log(
"An NFT w/ ID %s has been minted to %s",
newItemId,
msg.sender
);
// Increment the counter for when the next NFT is minted.
_tokenIds.increment();
emit NewNFTMinted(msg.sender, newItemId);
}
}
Writing smart contract is more or less like javascript but with some extra magic thanks to Solidity. Solidity is basically converted to byte code by the compiler. The byte code generated by the compiler is what lives in the blockchain.
We can use web3.py, web3.js or ether.js to interact with the smart contract which resides in the blockchain.
Running Locally with local blockchain
const main = async () => {
const nftContractFactory = await hre.ethers.getContractFactory("ShadowNFT");
const nftContract = await nftContractFactory.deploy();
await nftContract.deployed();
console.log("Contract deployed to:", nftContract.address);
// Call the function.
let txn = await nftContract.makeAnEpicNFT(
"data:application/json;base64,eyJkZXNjcmlwdGlvbiI6IkFuIE5GVCBmcm9tIHRoZSBoaWdobHkgYWNjbGFpbWVkIGdhbWUgb2YgdGhyb25lcyBjb2xsZWN0aW9uIiwicXVvdGUiOiJNeSBzd29yZC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EdWNGRENDhMM04yWno0PSJ9"
);
// Wait for it to be mined.
await txn.wait();
console.log("Minted NFT #1");
};
const runMain = async () => {
try {
await main();
process.exit(0);
} catch (error) {
console.error(error);
process.exit(1);
}
};
runMain();
Github
https://github.com/harshitsinghai77/web3-game-of-thrones-nft
Demo
https://game-of-thrones-nft.netlify.app/
Rarible Collection
Click here to see the collection
That’s it for today, see you soon. :)