my-nft
project run hardhat.config.js
file which is where we’ll set up our project in step 14.contracts/
is where we’ll keep your NFT smart contract code2.scripts/
is where we’ll keep scripts to deploy and interact with your smart contractMyNFT.sol
smart contract.MyNFT.sol
MyNFT.sol
file.@openzeppelin/contracts/token/ERC721/ERC721.sol
contains the implementation of the ERC-721 standard, which your NFT smart contract will inherit. Your smart contract must implement all the methods of the ERC-721 standard to be a valid NFT. To learn more about the inherited ERC-721 functions, check out the interface definition.@openzeppelin/contracts/utils/Counters.sol
provides counters that can only be incremented or decremented by one. Your smart contract uses a counter to keep track of the total number of NFTs minted and sets the unique ID on your new NFT. Each NFT minted using a smart contract must be assigned a unique ID—here your unique ID is just determined by the total number of NFTs in existence. For example, the first NFT we mint with your smart contract has an ID of "1," your second NFT has an ID of "2," etc.@openzeppelin/contracts/access/Ownable.sol
sets up access control on your smart contract, so only the owner of the smart contract (you) can mint NFTs. (Ownable
on line 10 and onlyOwner
on line 17.)ownerOf
, which returns the owner of the NFT, and transferFrom
, which transfers ownership of the NFT from one account to another.MyNFT
” and “NFT
.” The first variable is the smart contract’s name, and the second is its symbol. You can name each of these variables whatever you wish!mintNFT(address recipient, string memory tokenURI)
that allows us to mint an NFT! You'll notice this function takes two variables:address recipient
specifies the address that will receive your freshly minted NFTstring memory tokenURI
is a string that should resolve to a JSON document that describes the NFT's metadata. An NFT's metadata is really what brings it to life, allowing it to have configurable properties, such as a name, description, image, and other attributes. In part 2 of this tutorial, we will describe how to configure this metadata.mintNFT
calls some methods from the inherited ERC-721 library and ultimately returns a number that represents the ID of the freshly minted NFT. .env
file (just name it “.env”) in the root directory of your project, and add your MetaMask private key and HTTP Alchemy API URL..env
should now look like this:hardhat.config.js
file in step 14.hardhat.config.js
in the next step.hardhat.config.js
so that your project knows about them.hardhat.config.js
to look like this:deploy.js
with the following contents:const MyNFT = await ethers.getContractFactory("MyNFT");
const myNFT = await MyNFT.deploy();
deploy()
on a ContractFactory will start the deployment, and return a Promise that resolves to a Contract. This is the object that has a method for each of your smart contract functions..deploy()
function.