ERC-721 NFT Collection deployed on Ethereum Sepolia Testnet β portofolio Web3 project #2
- Minting Website: https://your-nft-collection.vercel.app
- Contract on Etherscan: https://sepolia.etherscan.io/address/YOUR_CONTRACT_ADDRESS
- Collection on OpenSea Testnet: https://testnets.opensea.io/collection/my-nft-collection
My NFT Collection adalah koleksi 100 NFT unik yang di-mint di jaringan Ethereum. Setiap NFT:
- Memiliki metadata dan gambar unik yang tersimpan di IPFS (via Pinata)
- Menggunakan standar ERC-721 (OpenZeppelin)
- Bisa di-mint langsung dari website menggunakan MetaMask
Proyek ini adalah portfolio project Web3 #2 β setelah sebelumnya membangun ERC-20 token.
| Layer | Teknologi |
|---|---|
| Smart Contract | Solidity 0.8.20 + OpenZeppelin 5.0 |
| Development | Hardhat |
| Storage | IPFS via Pinata |
| Frontend | React 18 + Ethers.js v6 |
| Network | Ethereum Sepolia Testnet |
| Verifikasi | Etherscan |
nft-collection/
βββ contracts/
β βββ MyNFTCollection.sol # Smart contract ERC-721
βββ scripts/
β βββ deploy.js # Deploy ke Sepolia
β βββ uploadToIPFS.js # Upload gambar & metadata ke IPFS
βββ test/
β βββ MyNFTCollection.test.js # Unit tests (opsional)
βββ assets/
β βββ images/ # File gambar NFT (1.png, 2.png, dst.)
βββ frontend/
β βββ public/
β β βββ index.html
β βββ src/
β βββ App.jsx # Komponen utama
β βββ App.css # Styling
β βββ config.js # ABI + contract address
β βββ hooks/
β βββ useWeb3.js # Custom hook Web3
βββ hardhat.config.js
βββ package.json
βββ .env.example # Template environment variables
βββ .gitignore
- Node.js v18+
- MetaMask browser extension
- Sepolia ETH (gratis dari faucet)
- Akun Alchemy atau Infura (RPC URL)
- Akun Pinata (IPFS upload)
git clone https://github.com/yourusername/nft-collection.git
cd nft-collection
# Install dependencies Hardhat
npm install
# Install dependencies frontend
cd frontend && npm install && cd ..# Copy template
cp .env.example .env
# Edit .env dan isi semua variabel:
nano .envVariabel yang dibutuhkan:
PRIVATE_KEY=your_wallet_private_key
SEPOLIA_RPC_URL=https://eth-sepolia.g.alchemy.com/v2/your_key
PINATA_API_KEY=your_pinata_api_key
PINATA_SECRET_API_KEY=your_pinata_secret
ETHERSCAN_API_KEY=your_etherscan_key # opsional# Taruh gambar NFT di folder assets/images/
# Nama file: 1.png, 2.png, 3.png, dst.
mkdir -p assets/images
# (taruh gambar di sini)
# Upload ke IPFS via Pinata
npm run upload-ipfsSetelah berhasil, copy metadataURI dari output ke frontend/src/config.js β array TOKEN_URIS.
# Compile kontrak
npm run compile
# Deploy ke Sepolia
npm run deploy:sepoliaOutput:
β
MyNFTCollection deployed!
Contract address: 0xABC...123
Copy contract address ke:
frontend/src/config.jsβCONTRACT_ADDRESS.envβREACT_APP_CONTRACT_ADDRESS
Setelah deploy, minting masih false (off) untuk keamanan. Aktifkan via Etherscan:
- Buka kontrak di Sepolia Etherscan
- Tab Contract β Write Contract
- Connect wallet (harus owner)
- Panggil
setMintingActive(true)
cd frontend
npm startBuka http://localhost:3000 β¨
| Fungsi | Akses | Keterangan |
|---|---|---|
mint(tokenURI) |
Public (payable) | Mint 1 NFT dengan harga mintPrice |
ownerMint(to, tokenURI) |
Owner | Mint gratis untuk airdrop |
setMintingActive(bool) |
Owner | Toggle minting on/off |
setMintPrice(price) |
Owner | Ubah harga mint |
withdraw() |
Owner | Tarik ETH dari kontrak |
totalSupply() |
Public | Total NFT ter-mint |
remainingSupply() |
Public | Sisa slot yang bisa di-mint |
canMint(address) |
Public | Cek apakah wallet bisa mint |
- β Reentrancy protection (Checks-Effects-Interactions pattern)
- β Max supply enforcement (100 NFT)
- β Per-wallet mint limit (max 5 per wallet)
- β Owner-only admin functions
- β Minting on/off switch
Setiap NFT mengikuti standar metadata OpenSea:
{
"name": "Genesis #1",
"description": "The first NFT of the collection.",
"image": "ipfs://CID_GAMBAR",
"attributes": [
{ "trait_type": "Rarity", "value": "Legendary" },
{ "trait_type": "Type", "value": "Genesis" },
{ "trait_type": "Network", "value": "Ethereum" }
]
}cd frontend
npm run build
# Install Vercel CLI
npm i -g vercel
# Deploy
vercel --prodTambahkan environment variable di Vercel Dashboard:
REACT_APP_CONTRACT_ADDRESS= alamat kontrak kamu
Membuat source code kontrak terlihat publik di Etherscan (bagus untuk portofolio):
npx hardhat verify --network sepolia YOUR_CONTRACT_ADDRESS "YOUR_WALLET_ADDRESS"Membangun proyek ini mengajarkan saya:
- ERC-721 standard β bagaimana NFT berbeda dari ERC-20 (unik vs fungible)
- IPFS & content addressing β metadata tidak tersimpan di blockchain langsung
- OpenZeppelin patterns β Ownable, URI Storage, Counters
- Ethers.js v6 β connect wallet, baca kontrak, kirim transaksi dari React
- Security patterns β Checks-Effects-Interactions untuk mencegah reentrancy
- OpenZeppelin Contracts Docs
- Hardhat Documentation
- Ethers.js v6 Docs
- Pinata IPFS
- Sepolia Faucet
- OpenSea Testnet
MIT License β lihat file LICENSE
Dibuat dengan β€οΈ sebagai portofolio Web3 project β membuktikan kemampuan full-stack blockchain development dari smart contract hingga frontend.
