Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🟨 NFT Project — Truffle Implementation

Triển khai NFT chuẩn ERC721 (OpenZeppelin) sử dụng Truffle Suite + Ganache.


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

  • Node.js (v16+ khuyến nghị)
  • npm hoặc yarn
  • Truffle: npm install -g truffle
  • Ganache: npm install -g ganache (hoặc dùng Ganache GUI)

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

truffle-nft/
├── contracts/          # Smart contract (NFT.sol)
├── migrations/          # Script deploy (migration files)
├── test/                 # Unit test (Mocha/Chai)
├── truffle-config.js     # Cấu hình network, compiler
└── .env                  # Biến môi trường (KHÔNG commit)

⚙️ Cài đặt

cd truffle-nft
npm install

Tạo file .env:

MNEMONIC="your twelve word seed phrase here"
SEPOLIA_RPC_URL=https://sepolia.infura.io/v3/<project_id>
ETHERSCAN_API_KEY=<your_key>

🧪 Chạy local với Ganache

Mở terminal riêng, chạy Ganache:

npx ganache

Compile contract:

truffle compile

Migrate (deploy) lên mạng local:

truffle migrate --network development

✅ Unit Test

truffle test

Bao gồm test event assertion (kiểm tra Transfer, Approval event khi mint/transfer NFT).


🐞 Debug

Cách 1 — console.log trong Solidity (qua Ganache): Thêm import "hardhat/console.sol";-tương tự hoặc dùng thư viện debug hỗ trợ Truffle, log ra trong quá trình chạy test.

Cách 2 — Truffle Debugger (chain forking):

truffle debug <transaction_hash> --network development

🚀 Deploy lên Testnet (Sepolia)

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

Dùng HDWallet Provider (đã cấu hình sẵn trong truffle-config.js):

truffle migrate --network sepolia

Hoặc dùng Truffle Dashboard (deploy an toàn hơn, không cần lưu private key):

truffle dashboard
# mở tab mới:
truffle migrate --network dashboard

🔍 Tương tác qua Truffle Console

truffle console --network sepolia
let instance = await MyNFT.deployed();
await instance.mint(myAddress, tokenId);

📄 License

MIT

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages