//test02
describe("Mint NFT", () => {
beforeEach(async () => {
const txResponse = await basicNft.mintNft()
await txResponse.wait(1)
})
it("Allows users to mint an NFT, and updates appropriately", async function () {
const tokenURI = await basicNft.tokenURI(0)
const tokenCounter = await basicNft.getTokenCounter()
assert.equal(tokenCounter.toString(), "1")
assert.equal(tokenURI, await basicNft.TOKEN_URI())
})
it("Show the correct balance and owner of an NFT", async function () {
const deployerAddress = deployer.address;
const deployerBalance = await basicNft.balanceOf(deployerAddress)
const owner = await basicNft.ownerOf("1")
assert.equal(deployerBalance.toString(), "1")
assert.equal(owner, deployerAddress)
})
})
})`
hardhat.config.js
`require("@nomiclabs/hardhat-waffle")
require("hardhat-gas-reporter")
require("@nomiclabs/hardhat-etherscan")
require("dotenv").config()
require("solidity-coverage")
require("hardhat-deploy")
// You need to export an object to set up your config
// Go to https://hardhat.org/config/ to learn more
/**
module.exports = {
defaultNetwork: "hardhat",
networks: {
hardhat: {
chainId: 31337,
forking: {
url: MAINNET_RPC_URL,
},
},
localhost: {
chainId: 31337,
},
goerli: {
url: GOERLI_RPC_URL,
accounts: [PRIVATE_KEY],
chainId: 5,
blockConfirmations: 6,
},
},
solidity: {
compilers: [
{
version: "0.8.7",
},
{
version: "0.6.12",
},
{
version: "0.4.19",
},
],
},
etherscan: {
apiKey: ETHERSCAN_API_KEY,
},
gasReporter: {
enabled: true,
currency: "USD",
outputFile: "gas-report.txt",
noColors: true,
// coinmarketcap: COINMARKETCAP_API_KEY,
},
namedAccounts: {
deployer: {
default: 0, // here this will by default take the first account as deployer
1: 0, // similarly on mainnet it will take the first account as deployer. Note though that depending on how hardhat network are configured, the account 0 on one network can be different than on another
},
},
}`
BasicNft.sol
` // SPDX-License-Identifier: MIT pragma solidity ^0.8.7;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
contract BasicNft is ERC721 { string public constant TOKEN_URI = "ipfs://bafybeig37ioir76s7mg5oobetncojcm3c3hxasyd4rvid4jqhy4gkaheg4/?filename=0-PUG.json"; uint256 private s_tokenCounter;
} `
01-deploy-basic-nft.js `const { network } = require("hardhat") const { developmentChains } = require("../helper-hardhat-config") const { verify } = require("../utils/verify")
module.exports = async ({ getNamedAccounts, deployments }) => { const { deploy, log } = deployments const { deployer } = await getNamedAccounts()
}
module.exports.tags = ["all", "basicnft", "main"]`
basicNft.test.js
`// We are going to skip a bit on these tests...
const { assert } = require("chai") const { network, deployments, ethers } = require("hardhat") const { developmentChains } = require("../../helper-hardhat-config")
//writing the test code from here..
!developmentChains.includes(network.name) ? describe.skip : describe("Basic NFT Unit Tests", function () { let basicNft, deployer
//test02 describe("Mint NFT", () => { beforeEach(async () => { const txResponse = await basicNft.mintNft() await txResponse.wait(1) }) it("Allows users to mint an NFT, and updates appropriately", async function () { const tokenURI = await basicNft.tokenURI(0) const tokenCounter = await basicNft.getTokenCounter()
hardhat.config.js
`require("@nomiclabs/hardhat-waffle") require("hardhat-gas-reporter") require("@nomiclabs/hardhat-etherscan") require("dotenv").config() require("solidity-coverage") require("hardhat-deploy") // You need to export an object to set up your config // Go to https://hardhat.org/config/ to learn more /**
const MAINNET_RPC_URL = process.env.MAINNET_RPC_URL || process.env.ALCHEMY_MAINNET_RPC_URL || "" const COINMARKETCAP_API_KEY = process.env.COINMARKETCAP_API_KEY || "" const GOERLI_RPC_URL = process.env.GOERLI_RPC_URL || "https://eth-goerli.alchemyapi.io/v2/your-api-key" const PRIVATE_KEY = process.env.PRIVATE_KEY || "0x11ee3108a03081fe260ecdc106554d09d9d1209bcafd46942b10e02943effc4a" const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY || ""
module.exports = { defaultNetwork: "hardhat", networks: { hardhat: { chainId: 31337, forking: { url: MAINNET_RPC_URL, }, }, localhost: { chainId: 31337, }, goerli: { url: GOERLI_RPC_URL, accounts: [PRIVATE_KEY], chainId: 5, blockConfirmations: 6, }, }, solidity: { compilers: [ { version: "0.8.7", }, { version: "0.6.12", }, { version: "0.4.19", }, ], }, etherscan: { apiKey: ETHERSCAN_API_KEY, }, gasReporter: { enabled: true, currency: "USD", outputFile: "gas-report.txt", noColors: true, // coinmarketcap: COINMARKETCAP_API_KEY, }, namedAccounts: { deployer: { default: 0, // here this will by default take the first account as deployer 1: 0, // similarly on mainnet it will take the first account as deployer. Note though that depending on how hardhat network are configured, the account 0 on one network can be different than on another }, }, }`