Skip to content

Hirosolo/database-uni-chain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

37 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽ“ UNI Chain Profile - Database & NFT Certificates Platform

๐ŸŽ“ A comprehensive platform for managing user profiles and NFT certificates with blockchain integration.

๐Ÿš€ Features

  • SIWE Authentication - Sign-In with Ethereum
  • Profile Management - Avatar, personal info with IPFS storage
  • NFT Certificate Sync - Fetch and display educational certificates from blockchain
  • Dual Sync Modes - EduHub registry or allowlist-based filtering
  • Auto Carousel - Beautiful NFT certificate display
  • Responsive UI - Modern design with Tailwind CSS

๐Ÿ›  Tech Stack

  • Frontend: Next.js 15.4.6, React 19, Tailwind CSS
  • Backend: Next.js API Routes
  • Database: PostgreSQL with Prisma ORM
  • Blockchain: Ethers.js, wagmi, RainbowKit
  • Storage: IPFS via Pinata
  • NFT Data: Alchemy API

๐Ÿ“‹ Environment Variables

Required for Production

# Database
DATABASE_URL="postgresql://username:password@host:port/dbname"

# Session Management
SESSION_SECRET="your-super-secret-key-minimum-32-characters"

# Blockchain Network
CHAIN_ID=84532
# Base Sepolia = 84532, Ethereum Sepolia = 11155111

# RPC Provider
RPC_URL="https://base-sepolia.g.alchemy.com/v2/${ALCHEMY_API_KEY}"
# For Ethereum Sepolia: https://eth-sepolia.g.alchemy.com/v2/${ALCHEMY_API_KEY}

# Alchemy API (for NFT data)
ALCHEMY_API_KEY="your-alchemy-api-key"
ALCHEMY_NETWORK="base-sepolia"
# Options: "base-sepolia", "eth-sepolia"

# IPFS Storage (choose one)
PINATA_JWT="your-pinata-jwt-token"
# OR
WEB3STORAGE_TOKEN="your-web3storage-token"

# NFT Contract Filtering
EDUHUB_CONTRACT="0x62cd4e0C5B0D4587861a21710ed15ba1823a6341"
CERT_CONTRACTS="0x53654af9b177adcceeff7c9c10112de21c75fbbd5,0x7eb5ec96b0a1d9d753c68d56a99e241782fde47f,0xc75de08a33d98620d9722acb51f7d1e49660c412"

# Next.js Public Variables
NEXT_PUBLIC_CHAIN_ID=84532
NEXT_PUBLIC_APP_NAME="UNI Chain Profile"
NEXT_PUBLIC_APP_URL="https://your-app.vercel.app"

# Optional: Cron/Task Security
TASK_SECRET="your-cron-task-secret"

# Development Only
TEST_USER_ADDRESS="0x286db307079C9C92b55D20b33e4eAB6d2A588E54"

๐Ÿš€ Deployment Guide

Prerequisites

  1. Vercel Account - vercel.com
  2. PostgreSQL Database - Managed service (Railway, PlanetScale, Supabase, etc.)
  3. Alchemy Account - For NFT data API
  4. Pinata Account - For IPFS storage

Step 1: Database Setup

  1. Create a PostgreSQL database on your preferred provider:

  2. Copy the DATABASE_URL connection string

Step 2: Vercel Deployment

  1. Connect Repository

    # Install Vercel CLI (optional)
    npm i -g vercel
    
    # Or deploy via GitHub integration
  2. Project Settings

    • Framework Preset: Next.js
    • Root Directory: web
    • Build Command: npm run build
    • Output Directory: .next
    • Install Command: npm install
  3. Environment Variables

    Go to your Vercel project โ†’ Settings โ†’ Environment Variables:

    DATABASE_URL=postgresql://...
    SESSION_SECRET=your-super-secret-key-minimum-32-characters
    ALCHEMY_API_KEY=your-alchemy-api-key
    ALCHEMY_NETWORK=base-sepolia
    CHAIN_ID=84532
    RPC_URL=https://base-sepolia.g.alchemy.com/v2/your-alchemy-api-key
    PINATA_JWT=your-pinata-jwt-token
    EDUHUB_CONTRACT=0x62cd4e0C5B0D4587861a21710ed15ba1823a6341
    CERT_CONTRACTS=0x53654af9b177adcceeff7c9c10112de21c75fbbd5,0x7eb5ec96b0a1d9d753c68d56a99e241782fde47f,0xc75de08a33d98620d9722acb51f7d1e49660c412
    NEXT_PUBLIC_CHAIN_ID=84532
    NEXT_PUBLIC_APP_NAME=UNI Chain Profile
    NEXT_PUBLIC_APP_URL=https://your-app.vercel.app
  4. Deploy

    git push origin main
    # Vercel will auto-deploy

Step 3: Database Migration

After first deployment, run database migration:

# Option 1: Via Vercel CLI
vercel env pull .env.local
npm run db:migrate

# Option 2: Via Vercel Functions (add build hook)
# Will run automatically during build

Step 4: Verify Deployment

Test these features:

  • โœ… Homepage loads
  • โœ… Connect wallet (MetaMask, etc.)
  • โœ… Sign-In with Ethereum (SIWE)
  • โœ… Profile page accessible
  • โœ… Avatar upload works
  • โœ… NFT certificate sync works
  • โœ… Profile editing and saving

๐Ÿ”ง Development Setup

# Clone repository
git clone https://github.com/Hpgbao2204/database-uni-chain.git
cd database-uni-chain

# Install dependencies
npm install

# Setup environment
cp web/.env.example web/.env
# Edit .env with your values

# Run database migration
cd web && npm run db:push

# Start development server
npm run dev

๐Ÿ“ Project Structure

database-uni-chain/
โ”œโ”€โ”€ web/                        # Next.js application
โ”‚   โ”œโ”€โ”€ app/                    # App router
โ”‚   โ”‚   โ”œโ”€โ”€ api/               # API routes
โ”‚   โ”‚   โ”œโ”€โ”€ profile/           # Profile page
โ”‚   โ”‚   โ””โ”€โ”€ page.tsx           # Homepage
โ”‚   โ”œโ”€โ”€ lib/                   # Utilities
โ”‚   โ”œโ”€โ”€ prisma/                # Database schema
โ”‚   โ””โ”€โ”€ public/                # Static files
โ”œโ”€โ”€ scripts/                   # Utility scripts
โ”œโ”€โ”€ readEduNFTScript.ts        # EduHub NFT reader
โ”œโ”€โ”€ readCertNFTScript.ts       # Allowlist NFT reader
โ””โ”€โ”€ README.md

๐Ÿ”— API Endpoints

  • GET /api/me - Get current user session
  • GET /api/nonce - Get SIWE nonce
  • POST /api/verify - Verify SIWE signature
  • GET /api/profile - Get user profile
  • POST /api/profile - Update user profile
  • POST /api/ipfs/upload - Upload file to IPFS
  • GET /api/sync-nfts - Get stored NFT certificates
  • POST /api/sync-nfts - Sync NFTs from blockchain

๐ŸŽฏ NFT Certificate Sync

Two modes available:

EduHub Registry Mode

POST /api/sync-nfts?mode=eduhub

Filters NFTs using EduHub contract's isEduNFT() function.

Allowlist Mode

POST /api/sync-nfts?mode=allowlist

Filters NFTs using predefined contract allowlist.

๐Ÿ› Troubleshooting

Common Issues

  1. Database Connection Error

    • Verify DATABASE_URL format
    • Check database server status
    • Ensure database exists
  2. SIWE Authentication Fails

    • Check SESSION_SECRET is set
    • Verify wallet network matches CHAIN_ID
    • Clear browser cookies/localStorage
  3. NFT Sync Not Working

    • Verify ALCHEMY_API_KEY is valid
    • Check contract addresses in CERT_CONTRACTS
    • Ensure target address has NFTs
  4. IPFS Upload Fails

    • Check PINATA_JWT token validity
    • Verify file size limits (2MB max)
    • Check file type restrictions

Production Debugging

# Check Vercel logs
vercel logs

# Database status
npm run db:studio

# Test NFT scripts locally
npm run nft:cert [address]

๐Ÿ” Security Considerations

  • โœ… Environment variables never exposed to client
  • โœ… Session secrets properly configured
  • โœ… SIWE message validation
  • โœ… File upload size/type restrictions
  • โœ… Database input sanitization

๐Ÿ“Š Monitoring

Monitor these metrics in production:

  • Database connection health
  • API response times
  • IPFS upload success rates
  • NFT sync success rates
  • User authentication flows

๐Ÿค Contributing

  1. Fork the repository
  2. Create feature branch (git checkout -b feature/amazing-feature)
  3. Commit changes (git commit -m 'Add amazing feature')
  4. Push to 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

For support and questions:


Built with โค๏ธ for the blockchain education community

  • PostgreSQL + Prisma database
  • Base Sepolia testnet support

โœ… Phase 2 - IPFS Profile System

  • Pinata IPFS upload แบฃnh avatar
  • Profile Management APIs (GET/POST)
  • File Validation (2MB limit, image types)
  • IPFS Gateway display images
  • Zod Schema Validation

๐Ÿ”„ Phase 3 - Roadmap

  • NFT Certificate sync tแปซ Base Sepolia
  • Advanced Profile fields (skills, achievements)
  • Profile Sharing & export features

๐Ÿ›  Tech Stack

Frontend

  • Next.js 14 (App Router)
  • TypeScript
  • TailwindCSS
  • RainbowKit + Wagmi
  • React Hook Form + Zod

Backend

  • Next.js API Routes
  • NextAuth.js (SIWE adapter)
  • Prisma ORM
  • PostgreSQL
  • Pinata IPFS API

Web3

  • Ethereum wallet support
  • Base Sepolia testnet
  • SIWE authentication
  • IPFS decentralized storage

๐Ÿš€ Quick Start

1. Clone Repository

git clone <repo-url>
cd database-uni-chain

2. Install Dependencies

pnpm install

3. Setup Environment

# Copy environment files
cp web/.env.example web/.env

# Update vแป›i credentials cแปงa bแบกn:
# - Database URL (PostgreSQL)
# - NextAuth Secret
# - Pinata JWT Token

4. Database Setup

cd web
pnpm db:push    # Tแบกo database schema

5. Start Development

pnpm dev        # Start Next.js server

Visit: http://localhost:3000

๐Ÿ“ Project Structure

database-uni-chain/
โ”œโ”€โ”€ web/                    # Next.js application
โ”‚   โ”œโ”€โ”€ app/
โ”‚   โ”‚   โ”œโ”€โ”€ api/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ auth/       # NextAuth.js routes
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ ipfs/       # IPFS upload API
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ profile/    # Profile management
โ”‚   โ”‚   โ”œโ”€โ”€ profile/        # Profile editing page
โ”‚   โ”‚   โ””โ”€โ”€ page.tsx        # Main dashboard
โ”‚   โ”œโ”€โ”€ lib/
โ”‚   โ”‚   โ”œโ”€โ”€ auth.ts         # NextAuth config
โ”‚   โ”‚   โ”œโ”€โ”€ db.ts          # Prisma client  
โ”‚   โ”‚   โ””โ”€โ”€ wagmi.ts       # Wagmi config
โ”‚   โ”œโ”€โ”€ prisma/
โ”‚   โ”‚   โ””โ”€โ”€ schema.prisma   # Database schema
โ”‚   โ””โ”€โ”€ components/         # React components
โ”œโ”€โ”€ contracts/              # Smart contracts (future)
โ”œโ”€โ”€ scripts/               # Deployment scripts
โ””โ”€โ”€ docs/                  # Documentation

๐Ÿ”ง API Endpoints

Authentication

  • GET /api/auth/session - Get current session
  • POST /api/auth/signin - SIWE login

Profile Management

  • GET /api/profile - Get user profile
  • POST /api/profile - Update profile

IPFS Upload

  • POST /api/ipfs/upload - Upload image to IPFS

๐ŸŽฏ Usage Guide

1. Connect Wallet

  • Click Connect Wallet
  • Chแปn wallet (MetaMask, Coinbase, etc.)
  • Switch to Base Sepolia network

2. Authenticate

  • Click Sign-In with Ethereum
  • Sign message trong wallet
  • Session sแบฝ ฤ‘ฦฐแปฃc tแบกo

3. Edit Profile

  • Click Edit Profile
  • Upload avatar image (โ‰ค2MB)
  • ฤiแปn thรดng tin: name, bio, email
  • Click Save Profile

4. View Profile

  • Avatar hiแปƒn thแป‹ tแปซ IPFS gateway
  • Profile data ฤ‘ฦฐแปฃc lฦฐu trong database
  • Share profile link vแป›i others

๐Ÿ” Environment Variables

# Database
DATABASE_URL="postgresql://..."

# NextAuth.js
NEXTAUTH_SECRET="random-secret-key"
NEXTAUTH_URL="http://localhost:3000"

# Pinata IPFS
PINATA_JWT="eyJhbGciOiJIUzI1NiIs..."

๐Ÿ‘‰ Chi tiแบฟt setup: Xem PINATA_SETUP.md

๐Ÿงช Testing

Manual Testing

  1. Start server: pnpm dev
  2. Connect wallet + authenticate
  3. Test profile upload & editing
  4. Verify IPFS image display

API Testing

# Test profile API
curl -X GET http://localhost:3000/api/profile

# Test IPFS upload (with auth)
curl -X POST http://localhost:3000/api/ipfs/upload \
  -H "Content-Type: multipart/form-data" \
  -F "file=@avatar.jpg"

๐Ÿ› Troubleshooting

Common Issues

"PINATA_JWT not configured"

"Wallet connection failed"

  • Switch to Base Sepolia testnet
  • Add network manually nแบฟu cแบงn

"Database connection error"

  • Kiแปƒm tra PostgreSQL running
  • Verify DATABASE_URL correct

"Image upload failed"

  • File size โ‰ค2MB
  • Supported formats: JPEG, PNG, WebP, GIF

๐Ÿ”ฎ Roadmap

Phase 3 - NFT Integration

  • Sync NFT certificates tแปซ Base Sepolia
  • Display achievements & credentials
  • Verify blockchain ownership

Phase 4 - Advanced Features

  • Skill verification system
  • Profile templates & themes
  • Export profile as PDF/JSON
  • Social sharing features

Phase 5 - Production

  • Mainnet deployment
  • Performance optimization
  • Security audit
  • Mobile app support

๐Ÿค Contributing

  1. Fork repository
  2. Create feature branch
  3. Make changes & test
  4. Submit pull request

๐Ÿ“„ License

MIT License - see LICENSE file

๐Ÿ“ž Support


Built with โค๏ธ for UNI Chain community

About

Database for UNI Chain

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors