A comprehensive Node.js API for Starknet wallet management with Telegram bot integration and MCP (Model Context Protocol) chat functionality.
- Node.js (v16 or higher)
- npm or yarn
- Supabase account and project
- Starknet RPC endpoint access
-
Clone and install dependencies:
npm install
-
Environment Setup: Create a
.envfile in the root directory with the following variables:# Server Configuration PORT=3000 NODE_ENV=development # Supabase Configuration SUPABASE_URL=your_supabase_project_url SUPABASE_ANON_KEY=your_supabase_anon_key SUPABASE_SERVICE_ROLE_KEY=your_supabase_service_role_key # Starknet Configuration STARKNET_RPC_URL=your_starknet_rpc_url STARKNET_NETWORK=sepolia # Telegram Bot (Optional) TELEGRAM_BOT_TOKEN=your_telegram_bot_token # MCP Configuration ANTHROPIC_API_KEY=your_anthropic_api_key # Security JWT_SECRET=your_jwt_secret_here ENCRYPTION_KEY=your_32_byte_encryption_key
-
Database Setup:
- Run the database migration scripts from the
migrations/folder - See
migrations/README.mdfor detailed instructions
- Run the database migration scripts from the
Development mode (with auto-reload):
npm run devProduction mode:
npm startThe server will start on http://localhost:3000
pagra-ai/
βββ src/ # Source code
β βββ config/ # Configuration files
β βββ helpers/ # Helper functions and utilities
β βββ services/ # Service layer (Telegram, etc.)
β βββ server.js # Main server file
βββ tests/ # Test files and utilities
β βββ mocks/ # Mock files for testing
β βββ *.test.js # Jest test files
β βββ test-*.js # Manual test scripts
β βββ README.md # Testing documentation
βββ migrations/ # Database migration scripts
β βββ *.sql # SQL migration files
β βββ README.md # Migration documentation
βββ docs/ # Documentation
β βββ telegram-setup.md # Telegram bot setup guide
β βββ mcp-chat-example.md # MCP chat examples
β βββ TEST_SCENARIOS.md # Testing scenarios
β βββ README.md # Documentation index
βββ .env # Environment variables (create this)
βββ package.json
βββ README.md # This file
POST /api/start- Create new wallet accountPOST /api/deploy_account- Deploy wallet to StarknetPOST /api/get_wallet_address- Get wallet addressPOST /api/get_balance- Check wallet balancePOST /api/transfer- Transfer fundsPOST /api/get_transactions- Get transaction history
POST /api/chat- Process chat messages with MCPPOST /api/chat/clear- Clear conversation historyGET /api/chat/history/:phone_number- Get chat history
POST /api/telegram/webhook- Telegram webhook endpointPOST /api/telegram/set-webhook- Set webhook URL
GET /health- Health check endpointGET /api-docs- Swagger API documentation
npm run dev- Start development server with nodemonnpm start- Start production servernpm test- Run Jest testsnpm run test:watch- Run tests in watch modenpm run test:coverage- Generate test coverage report
The project includes comprehensive testing:
- Automated Tests: Jest-based unit and integration tests
- Manual Tests: Interactive testing scripts
- Telegram Tests: Bot integration testing
- MCP Tests: Chat functionality testing
See tests/README.md for detailed testing instructions.
The project uses Supabase PostgreSQL with:
- Users table: Wallet and user information
- Transactions table: Transfer history and status
- Row Level Security: Secure data access
- Helper functions: Database utilities
See migrations/README.md for database setup instructions.
- β Create Starknet wallets
- β Deploy accounts to network
- β Transfer funds between wallets
- β Check balances and transaction history
- β Secure private key encryption
- β Interactive wallet operations via Telegram
- β Polling mode for development
- β Webhook mode for production
- β Natural language commands
- β MCP (Model Context Protocol) support
- β Context-aware conversations
- β Tool integration for wallet operations
- β Conversation history management
- β PIN-based authentication
- β Private key encryption
- β Rate limiting
- β Input validation
- β Row Level Security (RLS)
- Express - Web framework
- Supabase - Database and backend services
- Starknet.js - Starknet blockchain integration
- CORS - Cross-origin resource sharing
- Helmet - Security middleware
- Morgan - HTTP request logger
- express-rate-limit - Rate limiting
- node-telegram-bot-api - Telegram bot integration
- @anthropic-ai/sdk - Claude AI integration
- swagger-ui-express - API documentation
- Nodemon - Development auto-reload
- Jest - Testing framework
- Dotenv - Environment variable management
Comprehensive documentation is available in the docs/ folder:
- Telegram Setup: Complete bot integration guide
- MCP Chat Examples: AI chat functionality examples
- Test Scenarios: Testing strategies and procedures
- Never commit
.envfiles to version control - Use strong encryption keys (32 bytes minimum)
- Enable RLS policies in Supabase
- Validate all user inputs before processing
- Use HTTPS in production environments
- Regularly rotate API keys and secrets
- Supabase connection: Check environment variables and project status
- Starknet RPC errors: Verify RPC URL and network configuration
- Telegram bot issues: Ensure bot token is valid and webhook is set
- Database permissions: Run
migrations/fix-permissions.sql
- Check the relevant documentation in
docs/ - Review test files in
tests/for examples - Verify environment configuration
- Check server logs for detailed error messages
- Setup: Follow installation instructions
- Database: Run migrations from
migrations/ - Testing: Use test scripts in
tests/ - Documentation: Update relevant docs when adding features
- Deployment: Use production environment variables
- Set up your Supabase database using migration scripts
- Configure Telegram bot (optional) using
docs/telegram-setup.md - Test API endpoints using provided test scripts
- Implement additional features as needed
- Deploy to production environment