Skip to content

About

Chain Agent - an opBNB AI assistant; the repo's contents are the AI assistant, not a write-up of a final-year project.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

101 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

opBNB AI Assistant

A premium React + TypeScript application built on opBNB with AI-powered features, Supabase authentication, and seamless wallet integration.

opBNB AI Assistant

🚀 Features

  • 🤖 AI-Powered Assistant - Get instant help with blockchain queries and smart contract analysis
  • ⚡ Lightning Fast - Built on opBNB for ultra-low gas fees and 4,000+ TPS
  • 🔐 Secure Authentication - Email/password auth with Supabase
  • 💼 Auto Wallet Generation - Automatic opBNB wallet creation and secure storage
  • 🎨 Premium UI - Modern glassmorphic design with smooth animations
  • 📱 Fully Responsive - Works perfectly on all devices

🛠 Tech Stack

  • Frontend: React 18 + TypeScript + Vite
  • Styling: Custom CSS (No frameworks)
  • Animation: Framer Motion
  • Authentication: Supabase Auth
  • Database: Supabase PostgreSQL
  • Blockchain: ethers.js v6 + opBNB
  • State Management: Zustand
  • Encryption: crypto-js

🏗 Architecture

src/
├── components/          # React components
│   ├── Navbar.tsx      # Navigation with wallet status
│   ├── Hero.tsx        # Landing hero section
│   ├── Features.tsx    # Feature cards grid
│   ├── Stats.tsx       # opBNB performance stats
│   ├── Footer.tsx      # Footer with links
│   └── AuthModal.tsx   # Login/Signup modals
├── hooks/
│   └── useAuth.ts      # Authentication hook
├── lib/
│   ├── supabase.ts     # Supabase client config
│   └── wallet.ts       # Wallet utilities
├── services/
│   └── auth.ts         # Authentication service
├── store/
│   └── index.ts        # Zustand state management
├── styles/
│   ├── globals.css     # Global styles & variables
│   └── components.css  # Component-specific styles
└── sql/                # Database schema & queries

🗄️ Database Setup

1. Execute the SQL Schema

Run the following in your Supabase SQL editor:

-- Execute: sql/01_create_user_wallets_table.sql

This creates:

  • user_wallets table with encrypted private key storage
  • Row Level Security (RLS) policies
  • Automatic timestamp handling
  • Performance indexes

2. Table Structure

user_wallets:
- id (UUID, Primary Key)
- user_id (UUID, References auth.users)
- wallet_address (TEXT)
- encrypted_private_key (TEXT)  
- created_at (TIMESTAMP)
- updated_at (TIMESTAMP)

🔐 Security Features

  • Row Level Security: Users can only access their own wallet data
  • Private Key Encryption: AES encryption before database storage
  • Environment Variables: Sensitive data stored in .env
  • Secure Session Handling: Automatic session management with Supabase

⚙️ Environment Setup

Your .env file is already configured with:

VITE_SUPABASE_URL=https://your-project.supabase.co
VITE_SUPABASE_ANON_KEY=your_supabase_anon_key_here
VITE_ENCRYPTION_KEY=your_encryption_key_here

�️ Lighthouse IPFS Storage Setup (For NFT Images)

Why Lighthouse?

  • ✅ Simple - Just need an API key, no complex setup
  • ✅ Free Tier - Generous free storage for small projects
  • ✅ IPFS - Decentralized storage on IPFS network
  • ✅ Auto Fallback - Works without API key using embedded images

Getting Your FREE Lighthouse API Key

  1. Visit Lighthouse Website

    https://files.lighthouse.storage/
    
  2. Sign Up / Login

    • Click "Sign In" button
    • Connect your wallet (MetaMask, WalletConnect, etc.)
    • Complete the authentication
  3. Get Your API Key

    • After logging in, go to your dashboard
    • Navigate to "API Key" section in the sidebar
    • Click "Create New API Key" button
    • Copy your API key (format: xxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)
  4. Add to Your Project

    • Open .env file in your project root
    • Find the line: VITE_LIGHTHOUSE_API_KEY=your_lighthouse_api_key_here
    • Replace with your actual key: VITE_LIGHTHOUSE_API_KEY=your_actual_key_here
    • Save the file and restart your dev server

How It Works

With Lighthouse API Key:

✅ Images uploaded to IPFS
✅ Publicly accessible via: https://gateway.lighthouse.storage/ipfs/{hash}
✅ NFT metadata references IPFS URLs
✅ True decentralized storage

Without API Key (Automatic Fallback):

✅ Images converted to data URLs (base64)
✅ Embedded directly in NFT metadata
✅ NFTs still work perfectly
✅ No external dependencies
⚠️ Larger metadata size

Troubleshooting

Q: I see "Trial expired" error A: The trial API key has expired. Get a free API key from https://files.lighthouse.storage/

Q: Images aren't uploading to IPFS A: Check that your VITE_LIGHTHOUSE_API_KEY is set correctly in .env file

Q: Do I need an API key for NFTs to work? A: No! NFTs work without it using embedded images. The API key is only needed for IPFS storage.

Q: How much does Lighthouse cost? A: Lighthouse has a generous free tier. Check https://lighthouse.storage/ for current pricing.

More Information

See LIGHTHOUSE_SETUP.md for detailed documentation.

�📦 Installation & Usage

  1. Install dependencies (Already done!)
npm install
  1. Set up database
  • Go to your Supabase dashboard
  • Run the SQL scripts from sql/ folder
  • Verify RLS is enabled
  1. Start development server
npm run dev

🚀 Deployment

Build for Production

npm run build

Preview Build

npm run preview

🌟 User Flow

New Users (Signup)

  1. User visits homepage → clicks "Sign Up"
  2. Enters email/password → submits form
  3. Automatic wallet generation using ethers.js
  4. Private key encrypted with crypto-js AES
  5. User account + encrypted wallet stored in Supabase
  6. User logged in with wallet connected

Returning Users (Login)

  1. User clicks "Login" → enters credentials
  2. Supabase authenticates user
  3. Existing wallet fetched from database
  4. Private key decrypted securely
  5. Wallet restored → user logged in

Wallet Features

  • View wallet address (formatted: 0x1234...abcd)
  • Real-time balance updates
  • opBNB testnet integration
  • Secure transaction signing

🎨 UI/UX Features

Design System

  • Glassmorphic UI with backdrop blur effects
  • Dark Theme optimized for crypto applications
  • Gradient Accents for premium feel
  • Smooth Animations using Framer Motion
  • Responsive Design for all screen sizes

Components

  • Premium Navbar with wallet status
  • Hero Section with animated CTAs
  • Feature Cards with hover effects
  • Performance Stats for opBNB
  • Modal System for authentication

🔧 Development Scripts

npm run dev          # Start development server
npm run build        # Build for production
npm run preview      # Preview production build
npm run lint         # Run ESLint
npm run type-check   # TypeScript type checking

🌐 opBNB Integration

📝 API Reference

Authentication Service

AuthService.signUp(email, password)     // Create account + wallet
AuthService.signIn(email, password)     // Login + fetch wallet  
AuthService.getUserWallet(userId)       // Get user's wallet
AuthService.signOut()                   // Sign out user

Wallet Service

WalletService.generateWallet()          // Create new wallet
WalletService.encryptPrivateKey(key)    // Encrypt private key
WalletService.decryptPrivateKey(key)    // Decrypt private key
WalletService.getBalance(address)       // Get BNB balance
WalletService.formatAddress(address)    // Format for display

🗄️ SQL Commands for Supabase

Execute these in your Supabase SQL editor:

1. Main table creation:

# Copy and paste sql/01_create_user_wallets_table.sql

2. Verify setup:

  • Check Tables → user_wallets exists
  • Check Authentication → RLS enabled
  • Check SQL Editor → Run test queries from sql/02_useful_queries.sql

Built with ❤️ for the opBNB ecosystem languageOptions: { parserOptions: { project: ['./tsconfig.node.json', './tsconfig.app.json'], tsconfigRootDir: import.meta.dirname, }, // other options... }, }, ])


You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:

```js
// eslint.config.js
import reactX from 'eslint-plugin-react-x'
import reactDom from 'eslint-plugin-react-dom'

export default tseslint.config([
  globalIgnores(['dist']),
  {
    files: ['**/*.{ts,tsx}'],
    extends: [
      // Other configs...
      // Enable lint rules for React
      reactX.configs['recommended-typescript'],
      // Enable lint rules for React DOM
      reactDom.configs.recommended,
    ],
    languageOptions: {
      parserOptions: {
        project: ['./tsconfig.node.json', './tsconfig.app.json'],
        tsconfigRootDir: import.meta.dirname,
      },
      // other options...
    },
  },
])

About

Chain Agent - an opBNB AI assistant; the repo's contents are the AI assistant, not a write-up of a final-year project.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages