Skip to content

About

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

ย 

History

77 Commits

Folders and files

Repository files navigation

ERC1155 NFT Claim Application

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/

๐Ÿš€ Quick Start

Prerequisites

  • Node.js 18+
  • npm/yarn/pnpm
  • MetaMask or compatible Web3 wallet

Installation

# 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

๐Ÿ—๏ธ Project Architecture

Tech Stack

  • 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

Folder Structure

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

๐Ÿ”„ Data Flow Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   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  โ”‚                                           โ”‚
โ”‚  โ”‚                 โ”‚                                           โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐ŸŽฏ Key Benefits:

  • 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

๐Ÿ”— Smart Contract Integration

Contract Details

  • Standard: ERC1155
  • Network: Base Sepolia Testnet
  • Functions Used:
    • claim() - Mint NFTs to user wallet
    • getActiveClaimConditionId() - Get current claim phase
    • getClaimConditionById() - Get pricing and claim rules

Contract Data Source

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

๐Ÿš€ Performance Optimizations

Bundling & Routing

  • Next.js App Router: Automatic code splitting and route-based bundling

Data Fetching

  • 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' }

Image Optimization

  • Next.js Image Component: Automatic image optimization and lazy loading
  • IPFS Gateway: Efficient IPFS content delivery

Caching Strategy

  • React Query: 5-minute stale time, 30-minute garbage collection
  • Smart Contract Calls: Automatic caching for contract reads

โš ๏ธ Current Limitations

Scalability Constraints

  • 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

User Experience Gaps

  • 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

Technical Limitations

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

๐Ÿ”ฎ Future Improvements

Quick Wins

  • Add loading skeletons
  • Improve mobile design
  • Add transaction cost estimation before claiming
  • Create fallback images for broken IPFS links

Longer Term

  • Add pagination for large NFT collections
  • Implement search and filtering capabilities
  • Add WalletConnect for mobile wallet support

About

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages