A cutting-edge Next.js application that bridges traditional UPI payments with Web3 technology, enabling seamless cryptocurrency transactions through simple QR code scanning. Built with gas sponsorship, real-time conversion, and automated merchant payouts.
- Real-time Camera Scanning: Device camera integration for instant QR code detection
- Intelligent UPI Parsing: Advanced parsing engine supporting personal, static merchant, and dynamic merchant QR types
- Multi-format Support: Handles various UPI URI formats with comprehensive validation
- Error Recovery: Robust error handling with fallback mechanisms
- Live INR β USDC Conversion: Real-time rates via CoinGecko API with automatic updates
- Network-Optimized Fees: Chain-specific fee calculation for optimal cost efficiency
- Precision Processing: 6-decimal precision for accurate USDC transactions
- Rate Caching: Intelligent caching with 60-second refresh intervals
- Seamless Wallet Connection: Privy.io integration for frictionless user onboarding
- Gas Sponsorship: Complete ETH gas fee sponsorship - users pay only in USDC
- ERC-20 USDC Transfers: Secure token transfers with balance verification
- EIP-7702 User Operations: Advanced account abstraction with meta-transactions
- Multi-Chain Support: Native support for Arbitrum Sepolia and Ethereum Sepolia testnets
- Cashfree Integration: Enterprise-grade payout processing with test and production modes
- Instant Settlements: Automatic INR payouts to merchant UPI IDs upon successful transactions
- Beneficiary Management: Automated customer registration as Cashfree beneficiaries
- Real-time Status Tracking: Live payout status monitoring with detailed transaction logs
- Test Mode Support: Complete sandbox environment for development and testing
- Dynamic Customer Creation: Automated customer onboarding with UPI ID generation
- QR Code Generation: Custom QR code creation with embedded UPI payment details
- Beneficiary Registration: Seamless integration with Cashfree payout network
- Transaction History: Comprehensive logging and status tracking
- Node.js 18+ - Runtime environment
- MongoDB - Database for customer and transaction storage
- Web3 Wallet - MetaMask, Coinbase Wallet, or any Web3-compatible wallet
- Cashfree Account - For automated payout features (optional for basic scanning)
- CoinGecko API Key - For live currency conversion rates
- Clone the Repository
git clone <repository-url>
cd stableupi- Install Dependencies
yarn install- Environment Configuration
cp env.example .env.localEdit .env.local with your configuration:
# Web3 Configuration
NEXT_PUBLIC_CANDIDE_API_KEY=your_candide_api_key_here
NEXT_PUBLIC_TREASURY_ADDRESS=0xYourTreasuryAddressHere
CANDIDE_API_KEY=your_candide_api_key_here
# Database
DEVELOPMENT_MONGODB_URI=mongodb://localhost:27017/stableupi
PRODUCTION_MONGODB_URI=mongodb://localhost:27017/stableupi
# Currency Conversion
COINGECKO_API_KEY=your_coingecko_api_key
# Cashfree Payout (Optional - for automated payouts)
CASHFREE_APP_ID=your_test_app_id
CASHFREE_SECRET_KEY=your_test_secret_key
CASHFREE_CLIENT_ID=your_test_client_id
CASHFREE_CLIENT_SECRET=your_test_client_secret- Start MongoDB
# Using Docker
docker run -d -p 27017:27017 --name mongodb mongo:latest
# Or using local MongoDB installation
mongod- Run Development Server
yarn devOpen http://localhost:3000 to access the application.
- Navigate to
/scan - Connect your Web3 wallet
- Allow camera permissions
- Enter payment amount in INR
- Scan any UPI QR code
- Confirm the USDC transaction
- Setup Cashfree: Follow CASHFREE_SETUP.md
- Create Test Customers: Visit
/test/customers - Generate QR Codes: Create QR codes for test customers
- Enable Auto-Payout: Go to
/scanβ toggle "Auto Payout (Test Mode)" - Test Transactions: Scan customer QR codes and watch automated INR payouts
- Monitor Status: Check payout status in real-time
# Test UPI IDs
testuser@paytm
merchant@oksbi
customer@ybl
# Test Amounts
βΉ100 - βΉ1000 (recommended for testing)stableupi/
βββ app/ # Next.js App Router
β βββ api/ # API Routes
β β βββ 7702/ # EIP-7702 User Operations (Deprecated)
β β β βββ prepare-userop/ # User operation preparation
β β β βββ send-userop/ # User operation execution
β β βββ cashfree-beneficiary/ # Cashfree beneficiary management
β β β βββ [beneId]/ # Beneficiary-specific operations
β β β βββ add/ # Add new beneficiary
β β βββ conversion/ # Currency conversion services
β β β βββ inr-to-usd/ # INR to USDC conversion
β β βββ customers/ # Customer management
β β β βββ create/ # Create new customers
β β β βββ [customerId]/ # Customer-specific operations
β β β βββ qrcode/ # QR code generation
β β βββ payouts/ # Payout operations
β β β βββ initiate/ # Initiate payouts
β β β βββ status/ # Check payout status
β β βββ scans/ # QR code scanning
β β βββ server-info/ # Server information
β β βββ store-upi-transaction/ # Transaction storage
β β βββ update-upi-transaction/ # Transaction updates
β βββ scan/ # QR scanner page
β βββ server-info/ # Server info display
β βββ test/ # Test utilities
β β βββ customers/ # Customer test management
β βββ favicon.ico
β βββ globals.css # Global styles
β βββ layout.tsx # Root layout
β βββ page.tsx # Landing page
βββ components/ # React Components
β βββ ChainButtons.tsx # Network selection
β βββ Features.tsx # Features showcase
β βββ Footer.tsx # Site footer
β βββ Hero.tsx # Hero section
β βββ HowItWorks.tsx # How it works section
β βββ Navbar.tsx # Navigation
β βββ PrivyProvider.tsx # Web3 provider
β βββ scan-route/ # QR scanner components
β β βββ ScanPage.tsx # Main scanner interface
β βββ SwitchNetwork.tsx # Network switching
βββ config/ # Configuration files
β βββ constant.ts # App constants and settings
βββ context/ # React Context
β βββ WalletContext.tsx # Wallet state management
βββ lib/ # Utility libraries
β βββ abstractionkit.ts # Web3 abstraction utilities
β βββ cashfree.ts # Cashfree API client
β βββ chain-validation.ts # Blockchain validation
β βββ chains.ts # Chain configurations
β βββ dbConnect.ts # Database connection
β βββ getCollections.ts # Database collections
β βββ privy.ts # Privy authentication
β βββ qr-generator.ts # QR code generation
β βββ qr-storage.ts # QR data storage
β βββ upi.ts # UPI parsing utilities
βββ models/ # Database models
β βββ Customer.ts # Customer schema
β βββ Transactions.ts # Transaction schema
βββ types/ # TypeScript definitions
β βββ cashfree.types.ts # Cashfree API types
β βββ customer.types.ts # Customer types
β βββ upi.types.ts # UPI types
βββ public/ # Static assets
βββ node_modules/ # Dependencies
βββ package.json # Project metadata
βββ tsconfig.json # TypeScript config
βββ next.config.ts # Next.js config
βββ tailwind.config.js # Tailwind CSS config
βββ eslint.config.mjs # ESLint config
βββ env.example # Environment template
βββ README.md # Project documentation
POST /api/scans- Parse and validate UPI QR data{ "qrData": "upi://pay?pa=merchant@upi&pn=Test Merchant&am=100.00" }
POST /api/conversion/inr-to-usd- Convert INR to USDC with network fees{ "amount": 1000, "chainId": 421614 }
POST /api/customers/create- Create customer with UPI ID{ "name": "John Doe", "email": "john@example.com", "phone": "+919876543210", "upiId": "john@paytm" }GET /api/customers/[customerId]/qrcode- Generate customer QR code
POST /api/payouts/initiate- Initiate payout to beneficiary{ "beneficiaryId": "bene_123", "amount": 1000, "currency": "INR" }GET /api/payouts/status?transferId=transfer_123- Check payout status
POST /api/cashfree-beneficiary/add- Add new beneficiaryGET /api/cashfree-beneficiary/[beneId]- Get beneficiary details
POST /api/7702/prepare-userop- Prepare user operation (Deprecated)POST /api/7702/send-userop- Send user operation (Deprecated)
POST /api/store-upi-transaction- Store UPI transactionPOST /api/update-upi-transaction- Update transaction statusGET /api/server-info- Get server information
# ==========================================
# WEB3 CONFIGURATION
# ==========================================
# Candide API Key (Required for bundler and paymaster services)
CANDIDE_API_KEY=your_candide_api_key_here
NEXT_PUBLIC_CANDIDE_API_KEY=your_candide_api_key_here
# Treasury Address (Required for receiving payments)
NEXT_PUBLIC_TREASURY_ADDRESS=0xYourTreasuryAddressHere
# ==========================================
# DATABASE CONFIGURATION
# ==========================================
# MongoDB Connection Strings
DEVELOPMENT_MONGODB_URI=mongodb://localhost:27017/stableupi
PRODUCTION_MONGODB_URI=mongodb://your_production_mongodb_uri
# ==========================================
# EXTERNAL API KEYS
# ==========================================
# CoinGecko API (Required for currency conversion)
COINGECKO_API_KEY=your_coingecko_api_key
# ==========================================
# CASHFREE PAYOUT CONFIGURATION (Optional)
# ==========================================
# Test Mode Credentials
CASHFREE_APP_ID=CF_TEST_APP_ID
CASHFREE_SECRET_KEY=CF_TEST_SECRET_KEY
CASHFREE_CLIENT_ID=CF_TEST_CLIENT_ID
CASHFREE_CLIENT_SECRET=CF_TEST_CLIENT_SECRET
# Production Mode Credentials (Optional)
CASHFREE_APP_ID_PROD=CF_PROD_APP_ID
CASHFREE_SECRET_KEY_PROD=CF_PROD_SECRET_KEY
CASHFREE_CLIENT_ID_PROD=CF_PROD_CLIENT_ID
CASHFREE_CLIENT_SECRET_PROD=CF_PROD_CLIENT_SECRET
# Fund Source IDs (Optional)
CASHFREE_FUNDSOURCE_ID=CASHFREE_DEFAULT
CASHFREE_FUNDSOURCE_ID_PROD=your_production_fundsource_id
# ==========================================
# APPLICATION URLS (Optional)
# ==========================================
NEXT_PUBLIC_DEVELOPMENT_URL=http://localhost:3000
NEXT_PUBLIC_PRODUCTION_URL=https://yourdomain.com- Candide API Key: Sign up at Candide Wallet
- CoinGecko API Key: Get from CoinGecko API
- Cashfree Credentials: Register at Cashfree β Developers β API Keys
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β User Wallet β β StableUPI App β β Cashfree API β
β β β β β β
β β’ MetaMask βββββΊβ β’ QR Scanner βββββΊβ β’ Payout API β
β β’ Coinbase β β β’ Currency Conv β β β’ Beneficiary β
β β’ Privy Auth β β β’ Web3 Tx β β β’ Status Check β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β β β
βΌ βΌ βΌ
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Blockchain β β Database β β CoinGecko API β
β β β β β β
β β’ USDC Transfer β β β’ Customers β β β’ Exchange Ratesβ
β β’ Gas Sponsor β β β’ Transactions β β β’ Rate Cache β
β β’ Multi-Chain β β β’ Payout Status β β β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
- QR Scan β Parse UPI data β Validate merchant details
- Currency Conversion β INR to USDC β Add network fees
- Web3 Transaction β Prepare meta-transaction β Sign & execute
- Merchant Payout β Register beneficiary β Initiate transfer β Track status
- Next.js 15 - React framework with App Router
- React 19 - UI library with concurrent features
- TypeScript - Type-safe JavaScript
- Tailwind CSS v4 - Utility-first CSS framework
- Lucide React - Beautiful icon library
- Next.js API Routes - Serverless API endpoints
- MongoDB - NoSQL database for customer/transactions
- Mongoose - MongoDB object modeling
- Privy.io - Web3 wallet authentication
- Ethers.js v6 - Ethereum blockchain interaction
- AbstractionKit - Account abstraction utilities
- Viem - Lightweight Ethereum library
- @zxing/library - QR code scanning and generation
- Cashfree Payout API - Automated INR payouts
- CoinGecko API - Live cryptocurrency prices
- Candide Services - Bundler and paymaster for gas sponsorship
# Development
yarn dev # Start development server with Turbopack
yarn dev:debug # Start with debug mode
# Production
yarn build # Build for production with Turbopack
yarn start # Start production server
# Quality & Testing
yarn lint # Run ESLint
yarn type-check # TypeScript type checking
# Database
yarn db:seed # Seed database with test data
yarn db:migrate # Run database migrations-
Local Development
yarn dev # Visit http://localhost:3000 -
Testing Features
# Test QR scanning: http://localhost:3000/scan # Test customer management: http://localhost:3000/test/customers # View server info: http://localhost:3000/server-info
-
Database Setup
# Start MongoDB locally or use Docker docker run -d -p 27017:27017 --name mongodb mongo:latest # Or install MongoDB locally brew install mongodb-community # macOS sudo apt install mongodb # Ubuntu
// 1. Camera access and scanning
const codeReader = new BrowserMultiFormatReader()
const result = await codeReader.decodeFromVideoDevice()
// 2. UPI URI parsing and validation
const parsedData = parseAndValidateQr(qrData)
// 3. Data formatting for display
const formattedData = formatQrDataForDisplay(parsedResponse)// Real-time INR to USDC conversion with caching
const conversion = await fetch('/api/conversion/inr-to-usd', {
method: 'POST',
body: JSON.stringify({ amount: 1000, chainId: 421614 })
})
// Response includes network fees and total cost
{
inrAmount: 1000,
usdAmount: 13.45,
usdcAmount: 13.45,
networkFee: 0.5,
totalUsdcAmount: 13.95
}// Prepare USDC meta-transaction with gas sponsorship
const { metaTransaction, send } = await prepareUSDCMetaTransaction({
recipient: treasuryAddress,
usdcAddress: USDC_CONTRACT_ADDRESSES[chainId],
amountUsdc: usdcAmount,
userSigner: signer,
chainId: chainId,
backendApiKey: apiKey
})
// Execute the transaction (gas-free for user)
await send()// 1. Register beneficiary with Cashfree
const beneficiary = await cashfreeService.addBeneficiary(customerDetails)
// 2. Initiate payout
const payout = await cashfreeService.initiatePayout({
beneficiaryId: beneficiary.id,
amount: inrAmount,
currency: 'INR'
})
// 3. Track status
const status = await cashfreeService.getPayoutStatus(payout.transferId)-
Connect Repository
# Install Vercel CLI npm i -g vercel # Deploy vercel --prod
-
Environment Variables
- Set all environment variables in Vercel dashboard
- Use production MongoDB URI
- Configure production Cashfree credentials
-
Domain Configuration
vercel domains add yourdomain.com
-
Build Docker Image
FROM node:18-alpine WORKDIR /app COPY package*.json ./ RUN yarn install --frozen-lockfile COPY . . RUN yarn build EXPOSE 3000 CMD ["yarn", "start"]
-
Run with Docker Compose
version: '3.8' services: stableupi: build: . ports: - "3000:3000" environment: - NODE_ENV=production depends_on: - mongodb mongodb: image: mongo:latest ports: - "27017:27017"
- Set
NODE_ENV=production - Configure production database
- Set production API keys and secrets
- Enable HTTPS/SSL
- Configure monitoring and logging
- Set up backup strategies
- Configure rate limiting
- Test all payment flows
# Check camera permissions
# Ensure HTTPS in production (required for camera access)
# Verify @zxing/library is properly imported# Verify NEXT_PUBLIC_CANDIDE_API_KEY is set
# Check if wallet is connected to supported network
# Ensure treasury address is configured# Verify COINGECKO_API_KEY is valid
# Check API rate limits
# Ensure network connectivity# Verify test credentials are correct
# Check beneficiary details format
# Ensure sufficient balance in Cashfree account# Check environment variables
console.log(process.env.CANDIDE_API_KEY)
# Test database connection
yarn db:connect
# Check API endpoints
curl -X GET http://localhost:3000/api/server-info
# Monitor MongoDB
docker logs mongodb| Code | Description | Solution |
|---|---|---|
| 400 | Bad Request | Check request format and parameters |
| 401 | Unauthorized | Verify API keys and credentials |
| 409 | Conflict | Check for duplicate entries |
| 500 | Server Error | Check server logs and environment |
-
Fork & Clone
git clone https://github.com/yourusername/stableupi.git cd stableupi -
Branch Strategy
git checkout -b feature/your-feature-name # or git checkout -b fix/issue-description -
Code Standards
yarn lint # Check code style yarn type-check # Verify TypeScript types
-
Testing
# Test QR scanning functionality # Test Web3 transactions on testnet # Test Cashfree payout flow
- Update documentation for new features
- Add tests for new functionality
- Ensure all lint checks pass
- Update CHANGELOG.md if needed
- Request review from maintainers
- Use TypeScript for all new code
- Follow existing naming conventions
- Add JSDoc comments for public APIs
- Keep components modular and reusable
- Handle errors gracefully
This project is licensed under the MIT License - see the LICENSE file for details.
- CASHFREE_SETUP.md - Cashfree integration guide
- API Documentation - Complete API reference
- Deployment Guide - Production deployment steps
- Next.js Docs: https://nextjs.org/docs
- Privy.io: https://docs.privy.io
- Cashfree API: https://docs.cashfree.com
- CoinGecko API: https://www.coingecko.com/en/api
- Ethers.js: https://docs.ethers.org
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Discord: Join our community server
- Report Vulnerabilities: security@yourdomain.com
- Security Policy: SECURITY.md
Built with β€οΈ for the future of Web3 payments
β Star this repo if you find it useful!
Report Bug β’ Request Feature β’ Contribute