A Web3 application for claiming ERC1155 NFTs built with Next.js 15, React 19, and wagmi v2. Users can connect their wallets, view NFT collections, and claim tokens directly from smart contracts.
๐ Live Demo: https://erc1155-claim.vercel.app/
- Node.js 18+
- npm/yarn/pnpm
- MetaMask or compatible Web3 wallet
# Clone the repository
git clone git@github.com:mpallares/erc1155-claim.git
cd erc1155-claim
# Install dependencies
npm install
### Development Commands
```bash
npm run dev # Start development server
npm run build # Build for production
npm run start # Start production server
npm run test # Run test suite
npm run lint # Run ESLint- Frontend Framework: Next.js 15 (App Router)
- React: React 19
- Web3 Integration: wagmi v2 + viem
- State Management: TanStack React Query (server state) + React local state
- Styling: Tailwind CSS v4
- TypeScript: Full type safety
- Testing: Vitest + Testing Library
- Deployment: Vercel
src/
โโโ app/ # Next.js App Router
โ โโโ api/nfts/ # API route for NFT data
โ โโโ globals.css # Global styles
โ โโโ layout.tsx # Root layout (Server Component)
โ โโโ page.tsx # Home page (Server Component)
โโโ components/ # React components
โ โโโ ui/ # Reusable UI components
โ โโโ icons/ # SVG icon components
โโโ hooks/ # Custom React hooks
โโโ lib/ # Core configurations
โโโ types/ # TypeScript definitions
โโโ abis/ # Smart contract ABIs
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ External API โ โ Smart Contract โ
โ โ โ (ERC1155) โ
โ โข NFT metadata โ โ โข Live prices โ
โ โข Contract addr โ โ โข Claim rules โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ โ
โ 1. Server Fetch โ 3. Client Reads
โ (Build/Request time) โ (Real-time)
โผ โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ SERVER SIDE โ
โ โ
โ โโโโโโโโโโโโโโโโโโโ โ
โ โ app/page.tsx โ โ
โ โ โ โ
โ โ const nfts = โ ๐ซ NOT CACHED โ
โ โ await fetch() โ โข Fresh on every request โ
โ โ โ โข { cache: 'no-store' } โ
โ โโโโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โ 2. Pass initial data as props โ
โ โผ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ CLIENT SIDE โ
โ โ
โ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โ
โ โ NFTContent โ โ React Query โ โ
โ โ โ โ Cache โ โ
โ โ โข Initial data โ โโโโโโโโโถโ โ โ
โ โ from server โ โ โ
CACHED โ โ
โ โ โ โ โข 5min fresh โ โ
โ โ โ โโโโโโโโโโ โข 30min stored โ โ
โ โ โ โ โข Auto-refetch โ โ
โ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โ
โ โ โ โ
โ โ โ 4. Background Refetch โ
โ โ โ (when stale) โ
โ โ โผ โ
โ โ โโโโโโโโโโโโโโโโโโโ โ
โ โ โ /api/nfts โ โ
โ โ โ โ โ
โ โ โ โข Client fetch โ โ
โ โ โโโโโโโโโโโโโโโโโโโ โข Same endpoint โ โ
โ โ 5. Updated data โ โข Updates cache โ โ
โ โ โโโโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โผ โ
โ โโโโโโโโโโโโโโโโโโโ โ
โ โ UI Components โ โ
โ โ โ โ
โ โ โข NFTDetails โ โ
โ โ โข NFTList โ โ
โ โ โข Display data โ โ
โ โ โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
- Fast Initial Load: Server data shows immediately
- Always Fresh: Background updates keep data current
- Offline Resilient: Cached data works without network
- Smart Caching: Only refetch when actually stale
- Smooth UX: Updates happen in background
- Standard: ERC1155
- Network: Base Sepolia Testnet
- Functions Used:
claim()- Mint NFTs to user walletgetActiveClaimConditionId()- Get current claim phasegetClaimConditionById()- Get pricing and claim rules
The NFT metadata and contract addresses are fetched from an external API:
- API Endpoint:
https://mint-api-production-7d50.up.railway.app/nfts - Data Structure: Contains contract addresses, token IDs, metadata, and IPFS image URLs
- Next.js App Router: Automatic code splitting and route-based bundling
- Server Components: Initial NFT data fetched on the server for faster first load and SEO improvement
- No Cache Strategy: Fresh data on every request with
{ cache: 'no-store' }
- Next.js Image Component: Automatic image optimization and lazy loading
- IPFS Gateway: Efficient IPFS content delivery
- React Query: 5-minute stale time, 30-minute garbage collection
- Smart Contract Calls: Automatic caching for contract reads
- No pagination: All NFTs loaded at once (performance issue with 100+ NFTs)
- External API dependency: Single point of failure
- No search/filtering: Users must scroll through all NFTs
- Memory usage: Large collections consume significant browser memory
- No loading states: Not enough loading states, could be an issue with more NFTs
- Basic mobile experience: Although it has been implemented and the design doesn't break, could be improved
- Single network: Only supports Base Sepolia testnet
- Browser wallets only: No mobile wallet connect support (WalletConnect)
- No gas estimation: Users don't see transaction costs upfront
- Image fallbacks: No handling for broken IPFS images
- Local state only: Currently using only local component state and React Query cache; as the app scales with features we'll need to consider global state management solutions like Zustand and React Context to avoid prop drilling and maintain state consistency across components.
- Add loading skeletons
- Improve mobile design
- Add transaction cost estimation before claiming
- Create fallback images for broken IPFS links
- Add pagination for large NFT collections
- Implement search and filtering capabilities
- Add WalletConnect for mobile wallet support