This document outlines the optimized and consolidated crypto send/receive endpoints for NexusPay. The system now supports sending crypto to users via phone numbers, emails, or wallet addresses with enhanced security and multi-chain support.
- β Users can now send crypto to recipients using their email address
- β Email notifications are prepared for both sender and recipient
- β Case-insensitive email matching for better user experience
- β Support for 16+ blockchains (previously only 2)
- β Consistent chain validation across all endpoints
- β Better error messages with supported chain lists
- β
Removed redundant
POST /api/business/transfer-fundsendpoint - β
Removed duplicate
src/routes/mpesa.tsfile - β
Removed empty
src/routes/balanceRoutes.tsfile - β
All crypto transfers now use the optimized
sendTokenendpoint
- β Better error handling with standardized error codes
- β Enhanced input validation with descriptive error messages
- β Consistent response format across all endpoints
Endpoint: POST /api/token/sendToken
Purpose: Send crypto to users by phone number, email, or wallet address
Authentication: authenticate + Password OR Google Auth (user's choice)
Request Body:
{
"recipientIdentifier": "user@example.com", // Email, phone (+254712345678), or wallet address
"amount": 50.00,
"senderAddress": "0x...",
"chain": "arbitrum",
"tokenSymbol": "USDC", // Optional, defaults to USDC
"password": "userPassword", // Either password OR googleAuthCode (not both)
"googleAuthCode": "123456" // Either password OR googleAuthCode (not both)
}Security Requirements:
- $0 - $100: Password OR Google Auth (user chooses)
- $100+: Password OR Google Auth (user chooses)
Response:
{
"success": true,
"message": "Token sent successfully!",
"data": {
"transactionCode": "ABC123DEF4",
"amount": "50.00 USDC",
"recipient": "user@example.com",
"recipientAddress": "0x...",
"recipientPhone": "+254712345678",
"recipientEmail": "user@example.com",
"timestamp": "2025-01-27T10:30:00.000Z",
"transactionHash": "0x...",
"chain": "arbitrum",
"tokenSymbol": "USDC",
"notifications": ["SMS sent to recipient", "Email notification prepared for recipient"],
"securityLevel": "standard",
"authenticationMethod": "password",
"authenticationDetails": {
"method": "password",
"verified": true,
"transactionType": "low_value"
}
}
}Features:
- π Smart Recipient Lookup: Automatically finds users by phone, email, or wallet address
- π± Multi-Channel Notifications: SMS + Email notifications for both parties
- π Multi-Chain Support: Works across 16+ blockchains
- π‘οΈ Flexible Security: Password OR Google Auth - user's choice
- π° Amount-Based Security: Enhanced security for high-value transactions
Endpoint: POST /api/token/pay
Purpose: Pay registered businesses with crypto
Authentication: authenticate + Password OR Google Auth (user's choice)
Request Body:
{
"senderAddress": "0x...",
"merchantId": "MERCH123",
"amount": 100.00,
"confirm": true,
"chainName": "polygon",
"tokenSymbol": "USDT",
"password": "userPassword", // Either password OR googleAuthCode (not both)
"googleAuthCode": "123456" // Either password OR googleAuthCode (not both)
}Security Requirements:
- $0 - $100: Password OR Google Auth (user chooses)
- $100+: Password OR Google Auth (user chooses)
Response:
{
"success": true,
"message": "Payment to business completed successfully!",
"data": {
"businessName": "Example Store",
"businessAddress": "0x...",
"amount": 100.00,
"tokenSymbol": "USDT",
"chainName": "polygon",
"transactionHash": "0x...",
"timestamp": "2025-01-27T10:30:00.000Z",
"status": "completed",
"securityLevel": "standard",
"authenticationMethod": "google_auth",
"authenticationDetails": {
"method": "google_auth",
"verified": true,
"transactionType": "low_value_business_payment"
}
}
}Endpoint: GET /api/token/receive
Purpose: Get user's receive information (wallet address, phone, email, supported chains)
Authentication: authenticate (basic authentication)
Response:
{
"success": true,
"message": "Receive information retrieved successfully",
"data": {
"walletAddress": "0x...",
"phoneNumber": "+254712345678",
"email": "user@example.com",
"supportedChains": [
{ "name": "Arbitrum", "id": "arbitrum", "chainId": 42161 },
{ "name": "Polygon", "id": "polygon", "chainId": 137 },
{ "name": "Base", "id": "base", "chainId": 8453 },
{ "name": "Optimism", "id": "optimism", "chainId": 10 },
{ "name": "Celo", "id": "celo", "chainId": 42220 },
{ "name": "Avalanche", "id": "avalanche", "chainId": 43114 },
{ "name": "BNB Chain", "id": "bnb", "chainId": 56 },
{ "name": "Scroll", "id": "scroll", "chainId": 534352 },
{ "name": "Gnosis", "id": "gnosis", "chainId": 100 }
],
"note": "This wallet address works across all supported chains. Make sure to select the correct network when sending."
}
}Endpoint: GET /api/token/balance
Purpose: Get user's wallet balance across all supported chains
Authentication: authenticate (basic authentication)
Response:
{
"success": true,
"message": "User balance retrieved successfully",
"data": {
"walletAddress": "0x...",
"totalUSDValue": 1250.75,
"balances": {
"arbitrum": {
"USDC": 500.25,
"USDT": 250.50
},
"polygon": {
"USDC": 300.00,
"MATIC": 100.00
},
"celo": {
"cUSD": 200.00
}
},
"chainsWithBalance": 3,
"lastUpdated": "2025-01-27T10:30:00.000Z"
}
}- Arbitrum (Primary) - Chain ID: 42161
- Polygon - Chain ID: 137
- Base - Chain ID: 8453
- Optimism - Chain ID: 10
- Celo - Chain ID: 42220
- Avalanche - Chain ID: 43114
- BNB Chain - Chain ID: 56
- Scroll - Chain ID: 534352
- Gnosis - Chain ID: 100
- Ethereum - Chain ID: 1
- Fantom - Chain ID: 250
- Moonbeam - Chain ID: 1284
- Fuse - Chain ID: 122
- Aurora - Chain ID: 1313161554
- Lisk - Chain ID: 1890
- Somnia - Chain ID: 1919
- USDC (Primary stablecoin)
- USDT (Tether)
- BTC (Bitcoin)
- ETH (Ethereum)
- WETH (Wrapped Ethereum)
- WBTC (Wrapped Bitcoin)
- DAI (Dai)
- CELO (Celo native token)
- User Input: Recipient identifier (email/phone/wallet address)
- Smart Lookup: System automatically finds recipient by priority:
- Phone number (with or without + prefix)
- Email address (case-insensitive)
- Wallet address (direct)
- Validation: Chain and token validation
- Execution: Blockchain transaction with gas sponsorship
- Notifications: SMS + Email notifications to both parties
- Response: Transaction details with confirmation
- Phone Number: Most common, supports international format
- Email: Case-insensitive matching, supports all email formats
- Wallet Address: Direct blockchain address (0x...)
- Basic Auth: For reading wallet info and balances
- Flexible Security: For crypto transfers (Password OR Google Auth - user's choice)
- Low-Value Transactions (<$100): Password OR Google Auth
- High-Value Transactions ($100+): Password OR Google Auth (same options, enhanced logging)
- Input sanitization and validation
- Chain and token support verification
- Recipient existence verification
- Balance and allowance checks
- Flexible authentication method validation
- Standardized error codes and messages
- Detailed logging for debugging
- Graceful failure handling
- Security method guidance
- β Sent to both sender and recipient (if phone numbers available)
- β Transaction codes for verification
- β Amount and recipient details
- β Prepared for both sender and recipient (if emails available)
- β Transaction summaries
- β Security alerts
- β
POST /api/business/transfer-fundsβ Now handled bysendToken - β
src/routes/mpesa.tsβ Duplicate routes removed - β
src/routes/balanceRoutes.tsβ Empty file removed
- β
All crypto transfers now use the optimized
sendTokenendpoint - β Consistent validation and error handling
- β Unified notification system
- Parallel queries for better performance
- Optimized user lookup by multiple identifiers
- Efficient wallet creation for new users
- Standardized error response format
- Comprehensive error logging
- User-friendly error messages
- Gas sponsorship for seamless transactions
- Optimized blockchain interactions
- Efficient notification delivery
curl -X POST "http://localhost:8000/api/token/sendToken" \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"recipientIdentifier": "user@example.com",
"amount": 25.50,
"senderAddress": "0x...",
"chain": "polygon",
"tokenSymbol": "USDC"
}'curl -X POST "http://localhost:8000/api/token/sendToken" \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"recipientIdentifier": "+254712345678",
"amount": 100.00,
"senderAddress": "0x...",
"chain": "arbitrum",
"tokenSymbol": "USDT"
}'curl -X POST "http://localhost:8000/api/token/sendToken" \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"recipientIdentifier": "0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6",
"amount": 75.25,
"senderAddress": "0x...",
"chain": "base",
"tokenSymbol": "USDC"
}'- π Better User Experience: Send crypto to anyone using email, phone, or wallet address
- π Enhanced Security: OTP verification for all transfers
- π Multi-Chain Support: 16+ blockchains supported
- π± Smart Notifications: SMS + Email for both parties
- β‘ Improved Performance: Parallel queries and optimized logic
- π οΈ Maintainable Code: Consolidated endpoints, no redundancy
- π Better Error Handling: Standardized responses and detailed logging
- Email Service Integration: Implement actual email sending for notifications
- Push Notifications: Mobile app push notifications
- Batch Transfers: Send to multiple recipients at once
- Scheduled Transfers: Set up recurring crypto payments
- Advanced Analytics: Transaction insights and reporting
Last Updated: January 27, 2025
Version: 2.0.0
Status: β
Production Ready