Skip to content

Repository files navigation

🟦 NFT Project — Hardhat Implementation

Triển khai NFT chuẩn ERC721 (OpenZeppelin) sử dụng Hardhat.


📦 Yêu cầu hệ thống

  • Node.js (v16+ khuyến nghị)
  • npm hoặc yarn

📁 Cấu trúc thư mục

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)

⚙️ Cài đặt

cd hardhat-nft
npm install

Tạo file .env:

PRIVATE_KEY=<your_wallet_private_key>
SEPOLIA_RPC_URL=https://sepolia.infura.io/v3/<project_id>
ETHERSCAN_API_KEY=<your_key>

🛠️ Compile Contract

npx hardhat compile

✅ Unit Test

npx hardhat test

Hỗ trợ console.log trực tiếp trong Solidity để debug khi test:

import "hardhat/console.sol";
console.log("Owner:", owner);

🖥️ Chạy Local Node

npx hardhat node

Deploy lên mạng local (terminal khác):

npx hardhat run scripts/deploy.js --network localhost

🚀 Deploy lên Testnet (Sepolia)

Lưu ý: Goerli đã deprecated, dùng Sepolia thay thế.

npx hardhat run scripts/deploy.js --network sepolia

🔍 Verify Contract trên Etherscan

npx hardhat verify --network sepolia <deployed_contract_address> "<constructor_arg_1>" "<constructor_arg_2>"

🧩 Cấu hình mạng mẫu (hardhat.config.js)

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,
  },
};

📄 License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages