Deploy an NFT Contract - ERC721
Prerequisites:
Step 1: Set Up a New Hardhat Project
mkdir my-erc721-token
cd my-erc721-tokennpm init -ynpm install --save-dev hardhatnpx hardhat// contracts/Token.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract TestNFT is ERC721, Ownable {
constructor() ERC721("Test NFT", "NFT") {}
function mint(address to, uint256 tokenId) public onlyOwner {
_mint(to, tokenId);
}
}npm install @openzeppelin/contracts// hardhat.config.js
require("@nomiclabs/hardhat-waffle");
require("@nomiclabs/hardhat-ethers");
require("@nomiclabs/hardhat-etherscan");
module.exports = {
networks: {
// Add network configurations here (e.g., for local development, testnets, or mainnet).
VANAR_TESTNET:{
url: "RPC_VANAR_VANGAURD",
accounts: ["PRIVATE_KEY_OF_THE_DEPLOYER"],
chainId: 7860
}
},
etherscan: {
apiKey: "YOUR_ETHERSCAN_API_KEY", // Replace with your Etherscan API key
},
vanar: {
apiKey: "YOUR_VANAR_API_KEY", // Replace with your VANAR API key
}
solidity: "0.8.0",
};mkdir my-erc721-token
// scripts/deploy721.js
const { ethers, upgrades } = require("hardhat");
async function main() {
const [deployer] = await ethers.getSigners();
console.log("Deploying TestNFT from account:", deployer.address);
const TestNFT = await ethers.getContractFactory("TestNFT");
const testNFT = await TestNFT.deploy();
console.log("TestNFT deployed to:", testNFT.address);
await testNFT.deployed();
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
npx hardhat run scripts/deploy721.js --network <network_name>