Skip to content

amanning3390/raffles

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

43 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🎟️ Raffles - Non-Custodial Raffle Platform on Base

A fully decentralized, non-custodial raffle application built on Base (Coinbase's Layer 2). Raffle anything on-chain - ETH, ERC-20 tokens, or NFTs - with complete transparency and zero platform custody.

πŸ”’ Core Principles

  • 100% Non-Custodial: All funds locked in smart contracts. Platform has ZERO custody.
  • No KYC Required: Wallet-only authentication. Fully pseudonymous and privacy-first.
  • Provably Fair: All raffle mechanics verifiable on-chain with transparent winner selection.
  • Multi-Asset Support: Raffle ETH, any ERC-20 token, or any ERC-721 NFT on Base.

✨ Features

For Creators

  • βœ… Create raffles for ETH, any ERC-20 token, or any NFT
  • βœ… Customizable parameters (entry fee, max entries, duration, winner count)
  • βœ… Multiple winner support (1-10 winners per raffle)
  • βœ… Automatic prize distribution to winners
  • βœ… Entry fee collection (minus 0.5% platform fee)
  • βœ… Cancel raffles with full refunds if needed

For Participants

  • βœ… Browse active raffles with filtering (All/ETH/Tokens/NFTs)
  • βœ… Enter raffles with customizable entry count
  • βœ… View live raffle stats and progress
  • βœ… Automatic winner selection using provably fair randomness
  • βœ… Direct prize claiming from smart contract
  • βœ… Full refunds if raffle is cancelled

Platform Features

  • βœ… Modern, responsive UI with dark mode support
  • βœ… Real-time raffle statistics
  • βœ… User dashboard with created/entered/won raffles
  • βœ… Wallet-based authentication (Coinbase Smart Wallet, MetaMask, WalletConnect)
  • βœ… Toast notifications for transaction feedback
  • βœ… Loading states and error handling

πŸ› οΈ Tech Stack

Frontend:

  • Next.js 14 (App Router, React 19, TypeScript)
  • Tailwind CSS v4 with custom design system
  • OnchainKit v1.1+ (Coinbase's Base SDK for wallet, identity, transactions)
  • Wagmi v2 + Viem (Web3 interactions)
  • TanStack Query (State management and caching)
  • Neynar SDK (Optional Farcaster integration)

Smart Contracts:

  • Solidity 0.8.24
  • Foundry (Development framework)
  • Multi-asset support (ETH, ERC-20, ERC-721)
  • Non-custodial architecture
  • Provably fair winner selection

Deployment:

  • Vercel (Frontend hosting)
  • Base Sepolia (Testnet)
  • Base Mainnet (Production - coming soon)

πŸš€ Quick Start

Prerequisites

  • Node.js 18+
  • npm or yarn
  • A Web3 wallet (Coinbase Wallet recommended)
  • Base Sepolia ETH for testing (free from faucet)

1. Install Dependencies

npm install

2. Deploy Smart Contract

IMPORTANT: You must deploy the smart contract first before running the frontend.

See detailed instructions in:

  • Quick Guide: DEPLOYMENT_CHECKLIST.md
  • Full Guide: contracts/DEPLOYMENT.md

Quick deployment:

cd contracts
cp .env.example .env
# Edit .env with your private key and API keys
forge build
./deploy.sh

3. Configure Frontend

After deploying the contract, configure the frontend:

Option A - Interactive Setup (Recommended):

npm run setup
# Or: ./scripts/post-deploy-setup.sh

Option B - Manual Setup:

cp .env.example .env.local
# Edit .env.local and add:
# - Your deployed contract address
# - Alchemy API key
# - CDP API key
# - WalletConnect project ID

4. Run Development Server

npm run dev

Open http://localhost:3000

πŸ”§ OnchainKit Setup

This app uses OnchainKit for wallet connection, identity display, and transaction handling. OnchainKit is pre-configured but requires proper API keys.

Configuration

OnchainKit is configured in components/Providers.tsx with:

  • Chain: Base (mainnet) and Base Sepolia (testnet)
  • Wallet Support: Coinbase Smart Wallet (preferred), MetaMask, WalletConnect
  • Features: Identity (ENS/Basename), Avatar, Address display, Transaction components

Required Environment Variables

NEXT_PUBLIC_CDP_API_KEY=your_cdp_api_key_here
NEXT_PUBLIC_ALCHEMY_API_KEY=your_alchemy_api_key_here
NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID=your_walletconnect_project_id_here

Key Features Used

  1. Wallet Components: ConnectWallet, WalletDropdown, WalletDropdownDisconnect
  2. Identity Components: Avatar, Name, Address, EthBalance, Badge
  3. Transaction Components: Transaction, TransactionButton, TransactionStatus
  4. Smart Wallet: Coinbase Smart Wallet with gasless transactions (when available)

For detailed OnchainKit usage, see ONCHAINKIT_GUIDE.md.

🎭 Neynar SDK Setup (Optional)

Neynar SDK enables Farcaster integration for social features. This is completely optional - the app works without it.

What You Get With Neynar

  • SIWN Authentication: Sign In With Neynar for Farcaster identity
  • User Profiles: Display Farcaster usernames, avatars, and bios
  • Social Context: Show Farcaster verification status
  • Enhanced UX: Link wallet addresses to Farcaster identities

Setup Steps

  1. Get API Keys:

    # Sign up at https://neynar.com/
    # Create a project
    # Get your API key and Client ID
  2. Add to Environment:

    NEYNAR_API_KEY=your_neynar_api_key_here
    NEXT_PUBLIC_NEYNAR_CLIENT_ID=your_neynar_client_id_here
  3. Restart Dev Server:

    npm run dev

Graceful Degradation

If Neynar keys are not configured:

  • App continues to work normally
  • Farcaster features are hidden
  • Wallet-only authentication is used
  • No errors or warnings shown to users

For detailed Neynar integration, see NEYNAR_GUIDE.md.

πŸ”‘ Required API Keys

Get these API keys (all free tier available):

Required Keys

  1. Alchemy API Key (Required)

    • Sign up: https://www.alchemy.com/
    • Create a Base Sepolia app
    • Copy API key to NEXT_PUBLIC_ALCHEMY_API_KEY
    • Used for: RPC endpoints and blockchain data
  2. Coinbase Developer Platform (CDP) API Key (Required)

    • Sign up: https://portal.cdp.coinbase.com/
    • Create project
    • Copy API key to NEXT_PUBLIC_CDP_API_KEY
    • Used for: OnchainKit features (wallet, identity, transactions)
  3. WalletConnect Project ID (Required)

    • Sign up: https://cloud.reown.com/
    • Create project
    • Copy project ID to NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID
    • Used for: WalletConnect wallet connections

Optional Keys (For Enhanced Features)

  1. Neynar API Key (Optional)

    • Sign up: https://neynar.com/
    • Create project and get API key
    • Copy API key to NEYNAR_API_KEY
    • Copy client ID to NEXT_PUBLIC_NEYNAR_CLIENT_ID
    • Used for: Farcaster integration (SIWN authentication, user profiles)
    • Note: App works without this - Farcaster features will be disabled
  2. Basescan API Key (Optional)

πŸ—οΈ Project Structure

raffles/
β”œβ”€β”€ app/                          # Next.js App Router pages
β”‚   β”œβ”€β”€ page.tsx                  # Homepage (raffle browser)
β”‚   β”œβ”€β”€ create/                   # Create raffle flow
β”‚   β”œβ”€β”€ raffle/[id]/             # Individual raffle detail
β”‚   └── profile/[address]/       # User dashboard
β”œβ”€β”€ components/                   # React components
β”‚   β”œβ”€β”€ ui/                      # Reusable UI components
β”‚   β”‚   β”œβ”€β”€ button.tsx
β”‚   β”‚   β”œβ”€β”€ card.tsx
β”‚   β”‚   β”œβ”€β”€ input.tsx
β”‚   β”‚   β”œβ”€β”€ skeleton.tsx
β”‚   β”‚   β”œβ”€β”€ toast.tsx
β”‚   β”‚   └── error-boundary.tsx
β”‚   β”œβ”€β”€ raffle/                  # Raffle-specific components
β”‚   β”œβ”€β”€ wallet/                  # Wallet components
β”‚   └── Navbar.tsx               # Navigation
β”œβ”€β”€ contracts/                    # Smart contracts
β”‚   β”œβ”€β”€ src/                     # Solidity source files
β”‚   β”‚   β”œβ”€β”€ RaffleCore.sol      # Main raffle contract
β”‚   β”‚   └── interfaces/         # Contract interfaces
β”‚   β”œβ”€β”€ script/                  # Deployment scripts
β”‚   β”œβ”€β”€ test/                    # Contract tests
β”‚   └── DEPLOYMENT.md            # Deployment guide
β”œβ”€β”€ hooks/                        # React hooks
β”‚   └── useRaffleContract.ts    # Contract interaction hooks
β”œβ”€β”€ lib/                          # Utility libraries
β”‚   β”œβ”€β”€ contract.ts              # Contract ABI and config
β”‚   β”œβ”€β”€ wagmi.ts                 # Wagmi configuration
β”‚   └── neynar.ts                # Farcaster config (optional)
β”œβ”€β”€ scripts/                      # Helper scripts
β”‚   └── post-deploy-setup.sh    # Post-deployment setup
β”œβ”€β”€ DEPLOYMENT_CHECKLIST.md      # Step-by-step deployment
└── README.md                     # This file

πŸ“‹ Development Status

Phase 1: Foundation βœ… Complete

  • Next.js 14 setup with TypeScript
  • Tailwind CSS v4 configuration
  • Wagmi + OnchainKit integration
  • Wallet connection (Coinbase, MetaMask, WalletConnect)
  • Network switching (Base/Sepolia)
  • Neynar SDK setup (optional Farcaster integration)

Phase 2: Smart Contracts βœ… Complete

  • RaffleCore.sol with multi-asset support
  • ETH raffle functionality
  • ERC-20 token raffle functionality
  • ERC-721 NFT raffle functionality
  • Provably fair winner selection
  • Non-custodial architecture (no backdoors)
  • Deployment scripts and documentation

Phase 3: Core App Features βœ… Complete

  • Homepage with raffle browser and filters
  • Create raffle flow (multi-step form)
  • Raffle detail page with entry flow
  • User dashboard (created/entered/won)
  • Contract interaction hooks
  • Loading states and skeletons
  • Error handling and boundaries
  • Toast notification system
  • Responsive design with dark mode

Phase 4: Testing & Deployment πŸ”„ In Progress

  • Deploy to Base Sepolia testnet
  • Integration testing with live contracts
  • User acceptance testing
  • Bug fixes and optimizations

Phase 5: Advanced Features πŸ“‹ Planned

  • Raffle discovery and search
  • Token/NFT metadata display
  • Raffle analytics and charts
  • Social sharing (Farcaster frames)
  • Email notifications (optional)
  • Raffle templates

Phase 6: Production Launch πŸ“‹ Planned

  • Security audit
  • Deploy to Base Mainnet
  • Production monitoring
  • Documentation and guides
  • Community launch

πŸ” Troubleshooting

Wallet Connection Issues

Problem: "Wallet connection failed" or "Network error"

  • Solution: Ensure you're on Base Sepolia network. Click network switcher in wallet UI.
  • Solution: Check that NEXT_PUBLIC_ALCHEMY_API_KEY is set correctly.
  • Solution: Try disconnecting and reconnecting your wallet.

Problem: "Unsupported network"

  • Solution: Switch to Base Sepolia in your wallet or use the network switcher in the app.

Problem: Coinbase Smart Wallet not appearing

  • Solution: Ensure NEXT_PUBLIC_CDP_API_KEY is set correctly.
  • Solution: Clear browser cache and reload.

Transaction Issues

Problem: "Transaction failed" or "Insufficient funds"

Problem: Transaction stuck in pending

  • Solution: Check transaction on Basescan: https://sepolia.basescan.org/
  • Solution: Wait a few minutes - Base Sepolia can be slow during high traffic.

Problem: "Contract not deployed" error

  • Solution: Ensure you deployed the smart contract first (see contracts/DEPLOYMENT.md).
  • Solution: Verify NEXT_PUBLIC_RAFFLE_CORE_ADDRESS matches your deployed contract.

OnchainKit Issues

Problem: Identity components not showing ENS/Basename

  • Solution: This is normal - not all addresses have ENS/Basename. Address will be shown instead.

Problem: "CDP API key invalid"

Problem: Transaction component not rendering

  • Solution: Check browser console for errors.
  • Solution: Ensure wallet is connected before attempting transactions.

Neynar/Farcaster Issues

Problem: "Farcaster authentication failed"

  • Solution: Ensure NEYNAR_API_KEY and NEXT_PUBLIC_NEYNAR_CLIENT_ID are set.
  • Solution: Verify your Neynar API key is active at https://neynar.com/

Problem: Farcaster profile not loading

  • Solution: This is normal if the wallet address is not linked to a Farcaster account.
  • Solution: Check that the user has verified their address on Farcaster.

Problem: SIWN signature verification failed

  • Solution: Ensure you're signing with the same wallet that's connected.
  • Solution: Try disconnecting and reconnecting your wallet.

Build/Development Issues

Problem: "Module not found" errors

  • Solution: Run npm install to ensure all dependencies are installed.
  • Solution: Delete node_modules and .next, then run npm install again.

Problem: TypeScript errors

  • Solution: Run npm run build to see full error details.
  • Solution: Ensure you're using Node.js 18+ and latest npm.

Problem: Environment variables not loading

  • Solution: Ensure .env.local exists (not .env).
  • Solution: Restart dev server after changing environment variables.
  • Solution: Verify all NEXT_PUBLIC_* variables are prefixed correctly.

Getting Help

  • Check detailed guides: ONCHAINKIT_GUIDE.md and NEYNAR_GUIDE.md
  • Review contract deployment: contracts/DEPLOYMENT.md
  • Check deployment checklist: DEPLOYMENT_CHECKLIST.md
  • Open an issue on GitHub with error details

πŸ“„ License

MIT

🀝 Contributing

This is an open-source project. Contributions are welcome!

⚠️ Disclaimer

This application is provided as-is. Users are responsible for:

  • Compliance with local laws regarding raffles/contests
  • Understanding blockchain transactions are irreversible
  • Securing their own private keys and wallets

No KYC is performed by this platform. Use at your own risk.

Releases

Packages

Contributors

Languages