Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Environment variables
# Environment variables and secrets
.env
.env.local
.env.production
*.key
private_keys/
wallet_keys/

# Logs and temporary files
*.log
app.log
*.tmp

# Python virtual environment
venv/
Expand All @@ -16,4 +26,10 @@ build/
.idea/
.vscode/
*.swp
*.swo
*.swo

# macOS
.DS_Store

# Vercel
.vercel
58 changes: 58 additions & 0 deletions .vercelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Ignore files that are not needed for deployment to reduce size
venv/
__pycache__/
*.pyc
*.pyo
*.pyd
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# Test files
tests/
test_*.py
*_test.py
conftest.py

# Documentation
README.md
WEB_INTERFACE_README.md
DEPLOYMENT.md
PHANTOM_INTEGRATION.md
*.md

# Images (keep only essential ones)
images/

# Logs
*.log
app.log

# Git
.git/
.gitignore

# IDE
.vscode/
.idea/

# OS
.DS_Store
Thumbs.db

# Local development scripts
start_*.py
deploy-vercel.sh
48 changes: 48 additions & 0 deletions DEPLOYMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Vercel部署指南

## 环境变量配置

在Vercel控制台中,需要设置以下环境变量:

### 必需的环境变量:

1. **DEEPSEEK_API_KEY**
- 你的DeepSeek API密钥
- 从 https://platform.deepseek.com 获取

2. **AI_MODEL_PROVIDER**
- 设置为 `deepseek`
- 使用免费的DeepSeek AI模型

### 可选的环境变量:

3. **OPENAI_API_KEY** (可选)
- 如果想使用OpenAI而不是DeepSeek
- 需要将AI_MODEL_PROVIDER设置为 `openai`

## 部署步骤

1. 将代码推送到GitHub仓库
2. 在Vercel中导入项目
3. 配置环境变量
4. 部署

## 访问应用

部署完成后,访问你的Vercel URL即可使用Phantom钱包集成的Solana代理。

## 功能特性

- 🔒 安全的Phantom钱包集成
- 🤖 中文/英文自然语言处理
- 💰 钱包余额查询
- 📊 交易历史查看
- 🔄 代币操作
- 🆓 免费DeepSeek AI支持

## 技术栈

- Python Flask
- DeepSeek AI API
- Solana Web3.js
- Phantom Wallet SDK
210 changes: 210 additions & 0 deletions PHANTOM_INTEGRATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
# 👻 Phantom Wallet Integration

A secure, user-friendly integration with Phantom wallet that eliminates the need for private key management. Users can connect their existing Phantom wallet and interact with Solana using natural language commands.

## 🔥 Key Benefits

### 🔒 **Maximum Security**
- **No private keys in code** - Your keys never leave your browser
- **Wallet-controlled signing** - All transactions signed through Phantom
- **No custody risk** - You maintain full control of your assets
- **Browser-based security** - Leverages Phantom's security model

### 🎯 **User-Friendly**
- **One-click connection** - Connect wallet with single button click
- **Natural language** - Use plain English commands
- **Real-time feedback** - Instant balance checks and transaction status
- **Familiar interface** - Works with wallet you already use

### ⚡ **Zero Setup**
- **No funding wallet needed** - Use your existing wallet
- **No private key management** - Phantom handles all key operations
- **Simple .env** - Only OpenAI API key required
- **Quick start** - Running in under 2 minutes

## 🚀 Quick Start

### 1. Prerequisites
- [Phantom Wallet](https://phantom.app/) browser extension installed
- OpenAI API key

### 2. Setup
```bash
# Clone and setup
git clone <repository>
cd no-code-solana-agent
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Create .env file (only OpenAI key needed!)
cp .env.phantom.template .env
# Edit .env and add your OpenAI API key
```

### 3. Launch
```bash
# Start Phantom integration
python start_phantom_interface.py
```

### 4. Use
1. Open `http://localhost:5001` in your browser
2. Click "Connect Phantom"
3. Approve connection in Phantom popup
4. Start using natural language commands!

## 💬 Example Commands

### 📊 **Balance & Info**
```text
Check my wallet balance for all tokens
Show my wallet information
What's my SOL balance?
```

### 📈 **Transaction History**
```text
Show my recent transactions
View my transaction history
What are my latest transactions?
```

### 💸 **Send Operations**
```text
Send 0.1 SOL to 9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM
Transfer 5 USDC to my friend's wallet
Send 10 tokens to [address]
```

### 🎛️ **Account Management**
```text
Create an associated token account for USDC
Set up a new token account for PYUSD
Help me create a token account
```

## 🏗️ Architecture

### Frontend (`index_phantom.html`)
- **Phantom SDK Integration** - Direct connection to Phantom wallet
- **Responsive UI** - Clean, mobile-friendly interface
- **Real-time Status** - Live connection and transaction status
- **Error Handling** - Clear error messages and troubleshooting

### Backend (`app_phantom.py`)
- **RESTful API** - Clean endpoints for wallet operations
- **Natural Language Processing** - DSPy integration for command parsing
- **Solana RPC** - Direct blockchain queries for balances/history
- **Transaction Building** - Constructs transactions for wallet signing

### Agent (`agent_phantom.py`)
- **DSPy Framework** - Intelligent command interpretation
- **Security-First** - Wallet connection validation
- **Educational** - Explains operations and risks
- **Error Recovery** - Helpful troubleshooting guidance

## 🔐 Security Model

### What's Secure ✅
- Private keys never leave your browser
- All transactions signed in Phantom wallet
- No sensitive data stored on server
- Uses Phantom's proven security model
- Read-only operations don't need signatures

### What to Watch For ⚠️
- Always verify transaction details in Phantom before signing
- Check recipient addresses carefully
- Start with small amounts for testing
- Only use on trusted networks
- Keep Phantom wallet updated

## 🛠️ Development

### File Structure
```
phantom-integration/
├── index_phantom.html # Phantom-integrated frontend
├── app_phantom.py # Flask backend with wallet support
├── start_phantom_interface.py # Smart startup script
├── src/dspy_solana_wallet/
│ └── agent_phantom.py # Phantom-specific DSPy agent
└── .env.phantom.template # Environment template
```

### API Endpoints
- `POST /api/execute-phantom` - Execute natural language commands
- `POST /api/submit-transaction` - Submit signed transactions
- `GET /api/health-phantom` - Health check

### Extending Functionality
1. **Add new commands** - Update `process_phantom_command()` in `app_phantom.py`
2. **Enhance UI** - Modify `index_phantom.html`
3. **Improve agent** - Update prompts in `agent_phantom.py`

## 🔄 Migration from Private Key Version

### Easy Migration Path
1. Keep existing `.env` file (private key version still works)
2. Copy OpenAI key to new `.env.phantom.template`
3. Run Phantom version alongside existing version
4. Gradually migrate users to Phantom integration

### Side-by-Side Comparison

| Feature | Private Key Version | Phantom Integration |
|---------|-------------------|-------------------|
| **Security** | Keys in .env file | Keys in browser only |
| **Setup** | Complex wallet funding | One-click connection |
| **User Experience** | Technical setup required | Familiar wallet interface |
| **Transaction Signing** | Automatic | User-controlled |
| **Trust Model** | Trust server with keys | Zero-trust architecture |

## 🤝 Contributing

### Adding Features
1. Fork repository
2. Create feature branch
3. Add Phantom integration tests
4. Update documentation
5. Submit pull request

### Testing
```bash
# Test Phantom agent
python src/dspy_solana_wallet/agent_phantom.py

# Test API endpoints
curl -X GET http://localhost:5001/api/health-phantom
```

## 📚 Resources

- [Phantom Wallet Docs](https://docs.phantom.app/)
- [Solana Web3.js](https://solana-labs.github.io/solana-web3.js/)
- [DSPy Framework](https://github.com/stanfordnlp/dspy)
- [Solana Developer Docs](https://docs.solana.com/)

## 🐛 Troubleshooting

### Phantom Not Detected
- Install [Phantom wallet extension](https://phantom.app/)
- Refresh browser after installation
- Check browser console for errors

### Connection Failed
- Make sure Phantom is unlocked
- Try disconnecting and reconnecting
- Clear browser cache and cookies

### Transaction Errors
- Check wallet has sufficient balance
- Verify recipient address is valid
- Try with smaller amounts first

---

**Ready to get started? Run `python start_phantom_interface.py` and connect your Phantom wallet! 👻**
Loading