Triển khai NFT chuẩn ERC721 (OpenZeppelin) sử dụng Hardhat.
- Node.js (v16+ khuyến nghị)
- npm hoặc yarn
hardhat-nft/
├── contracts/ # Smart contract (NFT.sol)
├── scripts/ # Script deploy (deploy.js)
├── test/ # Unit test (Mocha/Chai + Ethers.js)
├── hardhat.config.js # Cấu hình network, compiler, plugin
└── .env # Biến môi trường (KHÔNG commit)
cd hardhat-nft
npm installTạo file .env:
PRIVATE_KEY=<your_wallet_private_key>
SEPOLIA_RPC_URL=https://sepolia.infura.io/v3/<project_id>
ETHERSCAN_API_KEY=<your_key>npx hardhat compilenpx hardhat testHỗ trợ console.log trực tiếp trong Solidity để debug khi test:
import "hardhat/console.sol";
console.log("Owner:", owner);npx hardhat nodeDeploy lên mạng local (terminal khác):
npx hardhat run scripts/deploy.js --network localhostLưu ý: Goerli đã deprecated, dùng Sepolia thay thế.
npx hardhat run scripts/deploy.js --network sepolianpx hardhat verify --network sepolia <deployed_contract_address> "<constructor_arg_1>" "<constructor_arg_2>"require("@nomicfoundation/hardhat-toolbox");
require("dotenv").config();
module.exports = {
solidity: "0.8.20",
networks: {
sepolia: {
url: process.env.SEPOLIA_RPC_URL,
accounts: [process.env.PRIVATE_KEY],
},
},
etherscan: {
apiKey: process.env.ETHERSCAN_API_KEY,
},
};MIT