Skip to content

Repository files navigation

🏁 Token Race - Crypto Betting Platform

A modern, decentralized crypto betting platform where users can bet on vetted tokens using USDC and compete in races based on price performance.

RainbowKit Supabase

πŸš€ Features

Core Functionality

  • Dynamic Race Duration: Flexible race durations from minutes to months
  • Real-time Price Tracking: Live price updates during races
  • Leaderboard System: Track performance and rankings
  • Web3-First Design: Wallet connection is all you need to start
  • Optional Email Auth: Enhanced features with Supabase account
  • Database Integration: Supabase PostgreSQL for bet history tracking
  • Responsive Design: Optimized for desktop and mobile

Technical Features

  • Modern React Stack: Built with React 18, Vite, and TypeScript
  • Web3 Integration: RainbowKit + wagmi for wallet connectivity
  • Database: Supabase PostgreSQL with Row-Level Security
  • Dual Authentication: Web3 wallet (required) + Email auth (optional)
  • Beautiful UI: Tailwind CSS with custom cyberpunk theme
  • Animations: Framer Motion for smooth interactions
  • Real-time Updates: React Query for data management
  • Environment Configuration: Secure dotenv-based configuration

Supported Networks

  • Ethereum Mainnet
  • Polygon
  • Sepolia Testnet

πŸ› οΈ Tech Stack

  • Frontend Framework: React 18.2.0
  • Build Tool: Vite 5.0.8
  • Database: Supabase (PostgreSQL)
  • Authentication: Web3 wallets (primary) + Supabase Auth (optional)
  • Styling: Tailwind CSS 3.4.0
  • Web3: RainbowKit 2.0.2 + wagmi 2.5.7
  • Animations: Framer Motion 10.16.16
  • Icons: Lucide React 0.294.0
  • Charts: Recharts 2.8.0
  • Notifications: React Hot Toast 2.4.1
  • Date Handling: date-fns 3.0.6

πŸ“¦ Installation

Prerequisites

  • Node.js 18+
  • npm or yarn
  • MetaMask or any Web3 wallet
  • Supabase account (optional, for bet history tracking)

Setup Instructions

  1. Clone the repository

    git clone <repository-url>
    cd token-race-frontend
  2. Install dependencies

    npm install
  3. Set up Supabase (Optional)

    a. Create a new Supabase project at supabase.com

    b. Get your project URL and anon key from the project settings

    c. Run the database migrations:

    # Copy the SQL from supabase/migrations/ files and run them in your Supabase SQL editor
    # Or use the Supabase CLI if you have it installed
  4. Configure environment variables Copy the example environment file and configure your settings:

    cp .env.example .env

    Edit .env and add your configuration:

    # Required: WalletConnect Project ID
    VITE_WALLET_CONNECT_PROJECT_ID=your_new_wallet_connect_project_id_here
    
    # Optional: Supabase Configuration (for bet history tracking)
    VITE_SUPABASE_URL=https://your-project-ref.supabase.co
    VITE_SUPABASE_ANON_KEY=your-anon-key-here
    
    # Optional: Custom RPC URLs (uses public RPCs if not provided)
    VITE_RPC_URL_MAINNET=your_mainnet_rpc_url_here
    VITE_RPC_URL_POLYGON=your_polygon_rpc_url_here
    VITE_RPC_URL_SEPOLIA=your_sepolia_rpc_url_here
    
    # Smart Contract Addresses
    VITE_RACE_CONTRACT_ADDRESS=0x1234567890123456789012345678901234567890
    VITE_USDC_CONTRACT_ADDRESS=0xA0b86a33E6441c8C06DD2b7c94b7E0e8c0c8c8c8
  5. Get your WalletConnect Project ID

    • Visit WalletConnect Cloud
    • Sign up or log in to your account
    • Click "Create New Project"
    • Enter your project details and copy your Project ID
    • Add it to your .env file
  6. Start the development server

    npm run dev
  7. Open your browser Navigate to http://localhost:5173 (or the port shown in terminal)

🎯 How It Works

Web3-First Approach

TOKEN RACE is designed with a Web3-first philosophy:

  1. Connect Wallet: Users simply connect their MetaMask or other Web3 wallet
  2. Start Betting: Immediately access all core features without any signup
  3. Optional Enhancement: Create an email account for bet history tracking and notifications

Authentication Levels

Level 1: Wallet Connection (Required)

  • βœ… Place bets on tokens
  • βœ… View current race status
  • βœ… Access all core betting features
  • βœ… View real-time leaderboards
  • ❌ Bet history tracking across sessions
  • ❌ Email notifications

Level 2: Email Account (Optional)

  • βœ… All Level 1 features
  • βœ… Persistent bet history tracking
  • βœ… Email notifications for race events
  • βœ… Enhanced profile management
  • βœ… Cross-device access to betting history

πŸ—„οΈ Database Schema

The application uses Supabase PostgreSQL with the following tables:

Users Table

users (
  id uuid PRIMARY KEY REFERENCES auth.users(id),
  wallet_address text UNIQUE,
  email text,
  created_at timestamptz DEFAULT now(),
  updated_at timestamptz DEFAULT now()
)

Bets Table

bets (
  id serial PRIMARY KEY,
  user_id uuid REFERENCES users(id),
  race_id text NOT NULL,
  token_address text NOT NULL,
  amount bigint NOT NULL,
  timestamp timestamptz DEFAULT now(),
  transaction_hash text,
  status text DEFAULT 'pending'
)

Security Features

  • Row-Level Security (RLS) enabled on all tables
  • Users can only access their own data
  • Authenticated users can view aggregate statistics
  • Secure helper functions for common queries

πŸ” Authentication Architecture

Primary Authentication: Web3 Wallets

  • Required for all core features
  • Supports MetaMask, WalletConnect, Coinbase Wallet, etc.
  • Instant access without any signup process
  • Secure wallet-based identity

Secondary Authentication: Email (Optional)

  • Enhances the experience with additional features
  • Supabase-powered email/password authentication
  • Enables bet history tracking and notifications
  • Can be added at any time after wallet connection

Route Protection

  • Protected routes require wallet connection
  • Enhanced features require email authentication
  • Graceful fallbacks for wallet-only users
  • Clear indicators of what features require email signup

πŸ—οΈ Project Structure

src/
β”œβ”€β”€ components/          # Reusable UI components
β”‚   β”œβ”€β”€ Layout.jsx      # Main layout with dual auth support
β”‚   β”œβ”€β”€ ProtectedRoute.jsx # Wallet-based route protection
β”‚   └── providers/      # Context providers
β”œβ”€β”€ contexts/           # React contexts
β”‚   └── AuthContext.jsx # Supabase authentication context
β”œβ”€β”€ hooks/              # Custom React hooks
β”‚   β”œβ”€β”€ useSupabaseSync.js # Sync user data between auth systems
β”‚   └── ...            # Other hooks
β”œβ”€β”€ lib/                # Utilities and configurations
β”‚   β”œβ”€β”€ supabase-helpers.js # Database helper functions
β”‚   └── ...            # Other utilities
β”œβ”€β”€ pages/              # Page components
β”‚   β”œβ”€β”€ LoginPage.jsx   # Optional email login
β”‚   β”œβ”€β”€ SignupPage.jsx  # Optional email signup
β”‚   └── ...            # Other pages
β”œβ”€β”€ supabase/           # Database migrations
β”‚   └── migrations/     # SQL migration files
└── ...

πŸ”§ Configuration

Environment Variables

Required Variables

  • VITE_WALLET_CONNECT_PROJECT_ID: Your WalletConnect Project ID

Optional Variables (Enhanced Features)

  • VITE_SUPABASE_URL: Your Supabase project URL
  • VITE_SUPABASE_ANON_KEY: Your Supabase anonymous key
  • VITE_RPC_URL_*: Custom RPC URLs for different networks
  • VITE_*_CONTRACT_ADDRESS: Smart contract addresses
  • VITE_ENABLE_*: Feature flags

Database Configuration (Optional)

  1. Create Supabase Project: Sign up at supabase.com

  2. Run Migrations: Execute the SQL files in supabase/migrations/ in order:

    • create_users_table.sql
    • create_bets_table.sql
    • create_helper_functions.sql
  3. Configure RLS: Row-Level Security is automatically enabled by the migrations

  4. Test Database: Use the Supabase dashboard to verify tables and policies

🎨 Design Philosophy

Web3-Native UX

  • Wallet-first design: Primary authentication method prominently featured
  • Progressive enhancement: Email features clearly marked as optional
  • Instant access: No barriers to entry for Web3 users
  • Clear value proposition: Users understand what they get with each auth level

Responsive & Accessible

  • Mobile-first design: Optimized for mobile Web3 browsers
  • Touch-friendly: Large touch targets and gesture support
  • Loading states: Smooth transitions during wallet connections
  • Error handling: Clear error messages and recovery options

πŸš€ Available Scripts

  • npm run dev - Start development server
  • npm run build - Build for production
  • npm run preview - Preview production build
  • npm run lint - Run ESLint

🌐 Deployment

Build for Production

npm run build

Environment Setup

Ensure all environment variables are configured in your deployment platform:

  • WalletConnect Project ID (required)
  • Supabase URL and keys (optional)
  • Contract addresses
  • Feature flags

Database Setup (Optional)

  1. Create production Supabase project
  2. Run all migration files in order
  3. Configure environment variables
  4. Test authentication and database access

πŸ”’ Security

  • Wallet-based security: Primary authentication through Web3 wallets
  • Row-Level Security: Database-level access control
  • Environment variables: Sensitive data protection
  • Input validation: Client and server-side validation
  • Secure Web3 interactions: Best practices implementation
  • Optional email auth: Additional security layer for enhanced features

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ†˜ Support

  • Documentation: Check the FAQ page in the app
  • Issues: Create an issue on GitHub
  • Discord: Join our community server
  • Email: support@tokenrace.com

πŸ—ΊοΈ Roadmap

  • Web3-first authentication system
  • Wallet-based access to all core features
  • Optional email authentication for enhanced features
  • Database schema with RLS
  • Bet history tracking for email users
  • Dynamic race duration system
  • Real-time leaderboards
  • Advanced analytics dashboard
  • Mobile app development
  • Multi-chain support expansion
  • DeFi integration

Built with ❀️ by the Token Race Team

Connect your wallet and start racing! 🏁

About

A modern, decentralized crypto betting platform where users can bet on vetted tokens using USDC and compete in races based on price performance.

Topics

Resources

Stars

7 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages