A comprehensive WhatsApp bot system with integrated smart wallet functionality, built with a modular architecture for secure and user-friendly blockchain interactions.
This project consists of three main components:
- Backend Bot - WhatsApp Web client that handles message processing and user interactions. For developement, to be replaced by whatsapp services.
- Server - REST API backend for user management, blockchain operations, and database management
- Frontend - Next.js web application providing a user interface for user registration and authorized operations, according to user preferences
- ๐ฑ WhatsApp Web integration using
whatsapp-web.js - ๐ฌ Interactive message handling and command processing
- ๐ค Automated session management
- ๐ฐ Deposit & Withdraw - Secure fund management
- ๐ธ Transfer - Send funds to other users
- ๐ On-ramp/Off-ramp - Convert between fiat and crypto
- ๐ก๏ธ Risk Management - Configurable risk profiles
- ๐ Authentication - Multi-factor authentication profiles and thresholds
- ๐ Transaction History - Complete audit trail
- ๐ณ USDC Integration - Stablecoin operations on Base network
- โ๏ธ Base Network Support - Sepolia testnet and mainnet
- ๐ฆ Smart Contracts - Vault integration
- ๐ Web3 Operations - Ethereum-compatible transactions
- ๐ก๏ธ Relayer Pattern - Gasless transactions for users
- ๐ฑ OnChainKit Integration - Coinbase's blockchain toolkit
- Node.js 18+ and npm
- WhatsApp account for bot authentication
-
Clone and navigate to the project
cd WhatsappBotBase/whatsapp-base-bot-smart-wallet -
Install dependencies for all components
# Backend Bot cd backend-bot && npm install && cd .. # Server cd server && npm install && cd .. # Frontend cd frontend && npm install && cd ..
-
Configure environment variables
Create
.envfiles in each component directory:Backend Bot (backend-bot/.env)
PORT=3001 BACKEND_API_URL=http://localhost:3002
Server (server/.env)
BACKEND_PORT=3002 JWT_SECRET=your-super-secret NETWORK=baseSepolia BASE_SEPOLIA_RPC=https://sepolia.base.org BASE_MAINNET_RPC=https://mainnet.base.org USDC_CONTRACT_ADDRESS=0x... VAULT_CONTRACT_ADDRESS=0x... # Your deployed vault contract PRIVATE_KEY=0x... # Relayer wallet private key
Frontend (frontend/.env.local)
NEXT_PUBLIC_API_URL=http://localhost:3002
-
Start all services
In separate terminals:
# Terminal 1 - Server cd server && npm run dev # Terminal 2 - Backend Bot cd backend-bot && npm run dev # Terminal 3 - Frontend cd frontend && npm run dev
-
Access the applications
- Frontend: http://localhost:3000
- Backend Bot: http://localhost:3001 (for QR code whathsapp login)
- Server API: http://localhost:3002
whatsapp-base-bot-smart-wallet/
โโโ backend-bot/ # WhatsApp Web client
โ โโโ services/ # Connection and backend services
โ โโโ handlers/ # Message processing
โ โโโ routes/ # API endpoints
โ โโโ public/ # Static files (QR code display)
โ โโโ server.js # Main bot server
โโโ server/ # Backend API
โ โโโ src/
โ โ โโโ config/ # Database and blockchain config
โ โ โโโ middleware/ # Authentication and security
โ โ โโโ routes/ # API route handlers
โ โ โโโ services/ # Business logic
โ โ โโโ utils/ # Utility functions
โ โ โโโ lib/ # Authentication management
โ โโโ server.ts # Main API server
โโโ frontend/ # Next.js web application
โ โโโ app/
โ โ โโโ actions/ # Wallet operation pages
โ โ โโโ components/ # React components
โ โ โโโ context/ # React context providers
โ โ โโโ utils/ # Frontend utilities
โ โ โโโ lib/ # Authentication management
โ โโโ next.config.ts # Next.js configuration
โโโ README.md # This file
-
QR Code Authentication
- Start the backend bot
- Navigate to http://localhost:3001
- Scan QR code with WhatsApp mobile app
- Bot will be ready when authentication completes
-
Message Commands
- Users can interact via WhatsApp messages
- Commands are processed by MessageHandler
- Responses include wallet operations and status updates
GET /api/health- Health checkPOST /api/auth/token/backend-bot- Get JWT token for backend-botPOST /api/auth/token/frontend- Get JWT token for frontend
POST /api/users/register- Register new userPOST /api/users/login- User loginGET /api/users/check/:whatsapp_number- Check user status
GET /api/wallet/balance/:userId- Get wallet balancePOST /api/vault/deposit- Deposit fundsPOST /api/vault/withdraw- Withdraw fundsGET /api/vault/deposits/:userId- Get deposit history
POST /api/transfers/send- Send transferGET /api/transactions/history/:userId- Transaction history
- PIN Encryption - Secure user PIN storage
- CORS Configuration - Cross-origin security
- JWT Authentication Service on server
- Origin Validation Middleware for request security
Development
- Use Base Sepolia testnet
- Enable debug logging
Production
- Use Base mainnet
- Production-grade PostgreSQL
- Enhanced security middleware
- Error monitoring
# Frontend deployment
cd frontend && npm run vercel:deploy
# Server deployment
cd server && npm run vercel:deploy- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
For support and questions:
- Check the documentation in each component's directory
- Review the architecture guides
- Open an issue on the repository
- Migration to Whatsapp Business API
- Add security features to server and frontend
- Multi-language support
- Integration with more blockchain networks
- Advanced trading features