Full-stack NFT marketplace on BNB Chain with ERC-721 minting, trading, and BugsCoin (ERC-20) payment integration. Built with Hardhat for smart contract development and React for the frontend.
Core Contracts:
NFT.sol- ERC-721 implementation with enumerable extensionNFTMarketplace.sol- Marketplace logic with listing/buying/offersIBugsCoin.sol- ERC-20 interface for payment tokenMockBugsCoin.sol- Test token for development
Governance:
NFTGovernance.sol- On-chain governance for marketplace parametersNFTGovernanceTimelock.sol- Timelock for proposal execution
- React 18.2 - Component-based UI
- Wagmi 2.14 + Viem 2.27 - Ethereum library with TypeScript support
- RainbowKit 2.2 - Multi-wallet connection modal
- React Router 6 - Client-side routing
- Tailwind CSS - Utility-first CSS framework
- Axios - HTTP client for API requests
- Web3.Storage - Decentralized storage for NFT metadata
NFT metadata stored on IPFS via Pinata:
- Image uploads
- JSON metadata
- Gateway:
https://gateway.pinata.cloud/ipfs/ - Backup gateway:
https://cloudflare-ipfs.com/ipfs/
- Minting with royalty support
- Token URI management
- Enumerable tokens (pagination support)
- Batch minting capability
- Burn functionality
- List NFTs for sale in BugsCoin
- Direct purchase
- Make offers
- Cancel listings
- Transfer ownership
- Marketplace fee (configurable)
- ReentrancyGuard on all state-changing functions
- Access control via Ownable
- SafeERC20 for token transfers
- Pausable contract for emergency stops
NFTMARKET/
├── contracts/ # Solidity smart contracts
│ ├── NFT.sol
│ ├── NFTMarketplace.sol
│ ├── IBugsCoin.sol
│ └── governance/
├── test/ # Contract tests
│ └── marketplace-test.js
├── hardhat.config.js # Hardhat configuration
└── frontend/ # React application
├── src/
│ ├── components/ # Reusable UI components
│ ├── pages/ # Route pages
│ ├── utils/ # Helper functions
│ ├── config/ # Configuration
│ └── abis/ # Contract ABIs
├── craco.config.js # Webpack customization
└── tailwind.config.js # Tailwind configuration
- Node.js 16+
- MetaMask or compatible Web3 wallet
- BNB for gas fees (testnet or mainnet)
Install dependencies:
npm installCompile contracts:
npx hardhat compileRun tests:
npx hardhat testDeploy to testnet:
npx hardhat run scripts/deploy.js --network testnetNavigate to frontend:
cd frontend
npm install
npm startDevelopment server runs on http://localhost:3000
Create .env in root:
PRIVATE_KEY=your_private_key
BSCSCAN_API_KEY=your_api_keyCreate frontend/.env.production:
REACT_APP_NFT_ADDRESS=0x...
REACT_APP_MARKETPLACE_ADDRESS=0x...
REACT_APP_BUGSCOIN_ADDRESS=0x...
REACT_APP_WALLET_CONNECT_PROJECT_ID=...
REACT_APP_WEB3_STORAGE_TOKEN=...Hardhat networks configured in hardhat.config.js:
- hardhat - Local development network
- bnbmainnet - BNB Chain Mainnet (chainId: 56)
- bnbtestnet - BNB Chain Testnet (chainId: 97)
RPC endpoints use environment variables with fallback to public RPCs.
Deploy all contracts:
npm run deploy:mainnetThis deploys:
- NFT contract
- Marketplace contract
- Sets up initial configuration
Deployment addresses saved to frontend/src/config/contracts.js
Build production bundle:
cd frontend
npm run buildBuild output in frontend/build/ ready for:
- Vercel
- Netlify
- IPFS hosting
- Any static host
Production build includes:
- Code obfuscation
- Source map removal
- Tree shaking
- Image optimization
- Unit tests for each contract
- Integration tests for marketplace flows
- Gas optimization tests
- Edge case coverage
Run with coverage:
npx hardhat coveragecd frontend
npm testContract optimization techniques:
- Packed storage variables
- Uint256 for loop counters
- Batch operations where possible
- Events for historical data
- Minimal storage reads
Average gas costs:
- Mint NFT: ~85k gas
- List for sale: ~55k gas
- Buy NFT: ~75k gas
- All contracts audited
- No proxy patterns (immutable deployment)
- Rate limiting on frontend
- Input validation at multiple layers
- Protection against common attacks (reentrancy, overflow, etc.)
Backend API (not included) should provide:
- NFT metadata caching
- User activity tracking
- Search and filtering
- Price history
- Analytics
- Chrome 90+
- Firefox 88+
- Safari 14+
- Edge 90+
- Brave
Mobile browsers supported via WalletConnect.
MIT License - See LICENSE file for details