ChainPaye is a WhatsApp bot built on the WhatsApp Business API that enables seamless cross-border payments using the Toronet blockchain. The bot allows users to easily send money, make payments, and manage their finances directly through WhatsApp.
- User Verification: Secure user onboarding with WhatsApp number verification
- Wallet Management: Integration with Toronet blockchain for wallet creation and management
- Cross-Border Payments: Send money between users in different countries (e.g., US to Nigeria, UK to Nigeria)
- Multi-Currency Support: Support for USD, EUR, GBP, and NGN
- Bank Integration: Deposit and withdraw funds to/from traditional bank accounts
- Peer-to-Peer Transfers: Send money directly to other ChainPaye users via WhatsApp
- Bank Transfers: Withdraw funds from your ChainPaye wallet to your bank account
- Currency Conversion: Convert between supported currencies (USD, EUR, GBP, NGN)
- Crypto Off-Ramp: Off-ramp crypto assets directly to fiat in under 50 seconds
- Payment Links: Generate payment links to receive payments in USD, EUR, GBP, or NGN
- Transaction History: View and track all your transactions
- Account Information: Check your wallet balances and account details instantly
- Flow-Based Interactions: Interactive WhatsApp Flows for seamless user experience
The bot supports both command-based and natural language triggers:
/banktransferor "withdraw" - Transfer from wallet to bank accounts/convertor "currency" - Convert between fiat currencies/depositor "top up" - Top up your ChainPaye wallet/myaccountor "balance" - View account details and balances/offrampor "sell crypto" - Off-ramp crypto to fiat/sendmoneyor "transfer" - Transfer money to another ChainPaye user/transactionhistoryor "history" - View past transactions
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ WhatsApp │ │ ChainPaye │ │ Toronet │
│ Business API │◄──►│ WhatsApp Bot │◄──►│ Blockchain │
└─────────────────┘ └─────────────────┘ └─────────────────┘
│
▼
┌─────────────────┐
│ MongoDB │
│ Database │
└─────────────────┘
│
▼
┌─────────────────┐
│ Redis │
│ Cache │
└─────────────────┘
chainpaye-whatsapp/
├── commands/ # Command handlers and routing
│ ├── handlers/ # Individual command handlers
│ │ ├── accountInfoHandler.ts
│ │ ├── conversionHandler.ts
│ │ ├── cryptoTopUpHandler.ts
│ │ ├── topUpHandler.ts
│ │ ├── transactionHandler.ts
│ │ ├── transferHandler.ts
│ │ └── withdrawalHandler.ts
│ ├── config.ts # Command configuration and triggers
│ └── route.ts # Command routing logic
├── config/ # Configuration files
│ ├── constants.ts # Application constants
│ └── database.ts # MongoDB connection configuration
├── jobs/ # Background jobs (Agenda)
│ ├── topUp/ # Top-up job definitions
│ ├── cryptoTopUp/ # Crypto top-up job definitions
│ ├── config.ts # Job configuration
│ ├── definitions.ts # Job definitions
│ ├── index.ts # Job initialization
│ └── types.ts # Job type definitions
├── models/ # Mongoose data models
│ ├── User.ts # User schema and methods
│ ├── Transaction.ts # Transaction schema and methods
│ └── Wallet.ts # Wallet schema and methods
├── services/ # External API integrations
│ ├── ToronetService.ts # Toronet blockchain API service
│ ├── TransactionService.ts # Transaction processing service
│ ├── UserService.ts # User management service
│ ├── WalletService.ts # Wallet operations service
│ ├── WhatsAppBusinessService.ts # WhatsApp Business API service
│ ├── redis.ts # Redis client configuration
│ └── ipdata.ts # IP geolocation service
├── utils/ # Utility functions
│ ├── countryCodeMapping.ts
│ ├── generateReceipt.ts
│ ├── logger.ts # Winston logging configuration
│ └── sendReceipt.ts
├── webhooks/ # Webhook handling
│ ├── controllers/ # Flow controllers
│ │ ├── conversion.controller.ts
│ │ ├── cryptoTopUp.controller.ts
│ │ ├── invoice.controller.ts
│ │ ├── setupPinFlow.controller.ts
│ │ ├── topUpFlow.controller.ts
│ │ ├── transferFlow.controller.ts
│ │ ├── userSetup.controller.ts
│ │ └── withdrawalFlow.controller.ts
│ ├── middlewares/ # Webhook middlewares
│ │ └── flowEncryption.middleware.ts
│ ├── route/ # Flow routes
│ ├── services/ # Flow services
│ ├── utils/ # Webhook utilities
│ ├── types/ # Type definitions
│ ├── encryption.ts # Encryption utilities
│ ├── flow.ts # Flow handling
│ ├── index.ts # Webhook entry point
│ └── middleware.ts # Express middleware
├── logs/ # Application logs
├── public/ # Static files
├── templates/ # Receipt templates
├── index.ts # Main application entry point
├── package.json
├── tsconfig.json
├── .env # Production environment variables
├── .env.development # Development environment variables
└── README.md
- Node.js - JavaScript runtime
- TypeScript - Type-safe JavaScript
- Express - Web framework for API endpoints
- MongoDB - NoSQL database for user data and transactions
- Mongoose - MongoDB object modeling for Node.js
- Redis - In-memory data store for caching and session management
- Agenda - Job scheduling for background tasks
- WhatsApp Business API - For WhatsApp integration and messaging (v24.0)
- WhatsApp Flows - Interactive flows for enhanced user experience
- Toronet Blockchain API - For blockchain operations and wallet management
- Helmet - Security middleware for Express
- Express Rate Limit - Rate limiting to prevent abuse
- Argon2 - Password hashing for PIN security
- Crypto-js - Encryption utilities
- Joi - Data validation
- Winston - Structured logging
- Axios - HTTP client for API calls
- dotenv - Environment variable management
- UUID - Unique ID generation
- Handlebars - Template engine for receipts
- Node.js 18+ installed
- MongoDB database access
- WhatsApp Business API credentials (v24.0)
- Toronet Blockchain API credentials
- Redis server for caching
-
Clone the repository
git clone <repository-url> cd Chainpaye
-
Install dependencies
pnpm install
-
Set up environment variables
The application automatically loads environment variables based on the
NODE_ENV:- Production: Loads from
.env - Development: Loads from
.env.development
# For development cp .env.example .env.development # For production cp .env.example .env
Edit the environment file with your configuration:
# Database MONGODB_URI=mongodb://localhost:27017/chainpaye # Redis REDIS_URL=redis://localhost:6379 # WhatsApp Business API (v24.0) GRAPH_API_TOKEN=your_access_token BUSINESS_PHONE_NUMBER_ID=your_phone_number_id VERIFY_TOKEN=your_verify_token APP_SECRET=your_app_secret # Private Key for Flow Encryption PRIVATE_KEY=your_private_key PASSPHRASE=your_passphrase # Toronet API TORONET_API_URL=https://api.toronet.com TORONET_ADMIN_ADDRESS=admin_username TORONET_ADMIN_PASSWORD=admin_password # Application NODE_ENV=development LOG_LEVEL=info PORT=3000
- Production: Loads from
-
Set NODE_ENV
# For development export NODE_ENV=development # For production export NODE_ENV=production
-
Build the application
pnpm build
-
Start the application
pnpm start
For development with hot reload:
pnpm dev
- whatsappNumber: User's WhatsApp phone number (unique identifier)
- firstName: User's first name
- lastName: User's last name
- email: User's email (optional)
- country: User's country code (ISO 3166-1 alpha-2)
- currency: User's default currency (USD, EUR, GBP, or NGN)
- isVerified: Account verification status
- toronetWalletId: Associated Toronet wallet ID
- pin: Security PIN for transactions (hashed with Argon2)
- userId: Reference to User model
- toronetWalletId: Toronet wallet identifier
- publicKey: Wallet public key
- balances: Stablecoin balances (ToroUSD, ToroNGN, etc.)
- isActive: Wallet activation status
- isFrozen: Wallet freeze status for security
- referenceId: Unique transaction reference
- type: Transaction type (payment, transfer, deposit, withdrawal, conversion, crypto-offramp)
- status: Transaction status (pending, processing, completed, failed)
- fromUser: Sender user reference
- toUser: Recipient user reference
- amount: Transaction amount
- currency: Transaction currency
- toronetTransactionId: Toronet blockchain transaction ID
- bankDetails: Bank account information for deposits/withdrawals
- User sends a message to the ChainPaye WhatsApp number
- Bot responds with an interactive WhatsApp Flow for user details
- User provides information (name, country, email)
- Account is created and verified
- User is prompted to set up a security PIN
- Verified user sets up a security PIN (4-6 digits)
- Bot creates Toronet wallet automatically
- Wallet is linked to user account
- User can now perform transactions
- User selects "Send Money" from menu or sends
/sendmoney - User enters recipient's WhatsApp number
- User enters amount and confirms currency
- User enters PIN for authentication
- Transaction is processed via Toronet blockchain
- Both parties receive confirmation messages
- User selects "Withdraw to Bank" or sends
/banktransfer - User selects withdrawal currency
- User enters amount and bank details
- User confirms with PIN
- Funds are transferred to user's bank account
- User receives confirmation
- User selects "Convert" or sends
/convert - User selects source and target currencies
- User enters amount
- System processes conversion
- User receives confirmation with new balances
- User selects "Off-ramp" or sends
/offramp - User selects crypto network
- User sends crypto to provided address
- System detects transaction and converts to fiat
- User receives fiat in wallet within 50 seconds
- PIN-based Authentication: 4-6 digit PIN required for all transactions (hashed with Argon2)
- WhatsApp Number Verification: Users verified through their WhatsApp number
- Session Management: Secure session handling with Redis
- Flow Token Encryption: Encrypted flow tokens for secure data exchange
- Encrypted Storage: Sensitive data encrypted in database
- API Security: Secure API communication with authentication tokens
- Webhook Signature Verification: Verify incoming webhook signatures
- Helmet: Security headers for Express
- Transaction Limits: Configurable limits for transactions
- Wallet Freezing: Ability to freeze wallets for security reasons
- Rate Limiting: Prevent abuse with rate limiting middleware
- Audit Logging: Comprehensive logging of all transactions and operations
- Message Templates: Pre-approved message templates for notifications
- Interactive Flows: WhatsApp Flows for enhanced user experience
- Webhook Handling: Process incoming messages and status updates
- Media Handling: Support for images, documents, and other media
- Read Receipts: Message read confirmation
- Typing Indicators: Show typing status for better UX
- Wallet Management: Create and manage blockchain wallets
- Transaction Processing: Send and receive stablecoin transactions
- Balance Queries: Real-time balance information
- Virtual Wallet Updates: Update virtual wallet for indirect transfers
- Exchange Rates: Current exchange rate information
- Structured Logging: Winston-based logging with multiple levels
- Log Rotation: Automatic log file rotation to manage disk space
- Error Tracking: Comprehensive error logging and reporting
- Health Checks: Application health check endpoint at
/ - Database Monitoring: MongoDB connection monitoring
- API Response Times: Track external API response times
- Transaction Metrics: Success rates, failure reasons, and volumes
- TypeScript: Strict TypeScript configuration for type safety
- Modular Architecture: Clear separation of concerns
- Error Handling: Comprehensive error handling throughout the application
- Service Layer Pattern: Business logic in service layer
The application uses environment-based dotenv loading:
- Development: Set
NODE_ENV=developmentto load from.env.development - Production: Set
NODE_ENV=productionto load from.env
This ensures sensitive production credentials are never used in development.
- Development: Local development with hot reload (
pnpm dev) - Production: Production environment with monitoring
- Set Environment: Configure
NODE_ENV=production - Install Dependencies: Run
pnpm install --production - Build Application: Run
pnpm build - Set Environment Variables: Ensure
.envis configured with production values - Start Application: Run
pnpm startor use a process manager like PM2
# Install PM2
npm install -g pm2
# Start application
pm2 start ecosystem.config.js
# View logs
pm2 logs chainpaye
# Restart application
pm2 restart chainpaye- Database Connection: Check MongoDB connection string and credentials
- API Authentication: Verify API keys and tokens for external services
- Message Delivery: Check WhatsApp Business API configuration and Flow IDs
- Transaction Failures: Review Toronet API responses and error codes
- Redis Connection: Ensure Redis server is running
- Log Analysis: Check application logs in the
logs/directory - API Testing: Test external APIs independently
- Database Queries: Verify database operations and data integrity
- Network Issues: Check network connectivity and firewall settings
- Clone the repository
- Create a feature branch
- Make changes with proper testing
- Create a pull request with description
- Code review and merge
- Functionality: Verify the feature works as expected
- Code Quality: Check for clean, maintainable code
- Testing: Ensure adequate test coverage
- Documentation: Update documentation as needed
MIT License - see LICENSE file for details
For support, email support@chainpaye.com or open an issue in the repository.