Skip to content

Statdapa/NFT-Collection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

β—ˆ My NFT Collection

ERC-721 NFT Collection deployed on Ethereum Sepolia Testnet β€” portofolio Web3 project #2

License: MIT Solidity Network OpenZeppelin

NFT Collection Preview

🌐 Live Demo


πŸ“‹ Deskripsi

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.


πŸ›  Tech Stack

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

πŸ“ Struktur Proyek

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

⚑ Quick Start

Prerequisites

  • Node.js v18+
  • MetaMask browser extension
  • Sepolia ETH (gratis dari faucet)
  • Akun Alchemy atau Infura (RPC URL)
  • Akun Pinata (IPFS upload)

1. Clone & Install

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 ..

2. Setup Environment Variables

# Copy template
cp .env.example .env

# Edit .env dan isi semua variabel:
nano .env

Variabel 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

3. Upload Gambar ke IPFS

# 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-ipfs

Setelah berhasil, copy metadataURI dari output ke frontend/src/config.js β†’ array TOKEN_URIS.

4. Compile & Deploy Smart Contract

# Compile kontrak
npm run compile

# Deploy ke Sepolia
npm run deploy:sepolia

Output:

βœ… MyNFTCollection deployed!
Contract address: 0xABC...123

Copy contract address ke:

  • frontend/src/config.js β†’ CONTRACT_ADDRESS
  • .env β†’ REACT_APP_CONTRACT_ADDRESS

5. Aktifkan Minting

Setelah deploy, minting masih false (off) untuk keamanan. Aktifkan via Etherscan:

  1. Buka kontrak di Sepolia Etherscan
  2. Tab Contract β†’ Write Contract
  3. Connect wallet (harus owner)
  4. Panggil setMintingActive(true)

6. Jalankan Frontend

cd frontend
npm start

Buka http://localhost:3000 ✨


πŸ“œ Smart Contract

Fungsi Utama

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

Fitur Keamanan

  • βœ… 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

πŸ–Ό NFT Metadata Format

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" }
  ]
}

πŸš€ Deploy Frontend ke Vercel

cd frontend
npm run build

# Install Vercel CLI
npm i -g vercel

# Deploy
vercel --prod

Tambahkan environment variable di Vercel Dashboard:

  • REACT_APP_CONTRACT_ADDRESS = alamat kontrak kamu

βœ… Verifikasi Kontrak (Opsional)

Membuat source code kontrak terlihat publik di Etherscan (bagus untuk portofolio):

npx hardhat verify --network sepolia YOUR_CONTRACT_ADDRESS "YOUR_WALLET_ADDRESS"

πŸ“š Yang Saya Pelajari

Membangun proyek ini mengajarkan saya:

  1. ERC-721 standard β€” bagaimana NFT berbeda dari ERC-20 (unik vs fungible)
  2. IPFS & content addressing β€” metadata tidak tersimpan di blockchain langsung
  3. OpenZeppelin patterns β€” Ownable, URI Storage, Counters
  4. Ethers.js v6 β€” connect wallet, baca kontrak, kirim transaksi dari React
  5. Security patterns β€” Checks-Effects-Interactions untuk mencegah reentrancy

πŸ”— Resources


πŸ“„ License

MIT License β€” lihat file LICENSE


Dibuat dengan ❀️ sebagai portofolio Web3 project β€” membuktikan kemampuan full-stack blockchain development dari smart contract hingga frontend.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors