A USSD-based Bitcoin Lightning payment system that integrates Africa's Talking USSD API, Python, MeTTa language for symbolic reasoning, and Bitcoin Lightning Network.
# Bitcoin Lightning USSD System
A USSD-based Bitcoin Lightning payment system that integrates Africa's Talking USSD API, Python Flask, MeTTa language for symbolic reasoning, and Bitcoin Lightning Network.
## π Features
- **USSD Interface**: Interactive USSD menus for Bitcoin Lightning payments
- **Lightning Network**: Support for LND, LNbits, and mock backends
- **MeTTa Integration**: Symbolic reasoning for state management and validation
- **M-Pesa Integration**: Simulated KES β Bitcoin conversions
- **Multi-language**: English and Swahili support
- **Real-time Balances**: Sync between MeTTa knowledge base and Lightning API
## π± USSD Menu Structure
```
Bitcoin Lightning
Balance: X sats
1. Send BTC β Enter phone β Enter amount β Confirm
2. Receive BTC β Enter amount β Get invoice code
3. Send Invoice β Enter phone β Enter amount β Send via SMS
4. Top Up M-Pesa β Enter KES β Enter M-Pesa code β Convert
5. Withdraw M-Pesa β Enter KES β Enter M-Pesa number β Convert
0. Exit
```
## ποΈ Architecture
```
USSD Request β Flask App β USSDHandlers β MeTTa + Lightning API
β
Africa's Talking Response
```
### Components
1. **app.py**: Flask USSD endpoint handling Africa's Talking protocol
2. **handlers.py**: Business logic with MeTTa integration
3. **lightning.py**: Lightning Network API wrapper (LND/LNbits/Mock)
4. **atoms_simple.metta**: MeTTa knowledge base for users, balances, rules
5. **test_ussd.py**: Test suite for USSD flows
## π οΈ Installation
### 1. Environment Setup
```bash
# Ubuntu setup
sudo apt update
sudo apt install python3.12-venv -y
# Create project
mkdir MeTTaProject
cd MeTTaProject
python3 -m venv venv
source venv/bin/activate
# Install dependencies
pip install hyperon==0.2.2 flask requests
```
### 2. Project Structure
```
MeTTaProject/
βββ app.py # Flask USSD handler
βββ handlers.py # Lightning + MeTTa functions
βββ lightning.py # Lightning API wrapper
βββ atoms_simple.metta # MeTTa knowledge b β¦