SUI Wallet Telegram Bot Documentation
๐ค Project Overview
A TypeScript-based Telegram bot that provides comprehensive SUI blockchain wallet management functionality. Users can create, import, and manage SUI wallets directly through Telegram, including balance checking, private key management, and SUI token transfers with slippage protection.
Repository: https://github.com/ecorey/tg_bot
๐ Security Notice
Security Audit Status
โ Repository Verified: This repository has been audited for security. No private keys or sensitive information are exposed in the codebase.
- โข All API keys and tokens are stored in environment variables
- โข Configuration files with sensitive data are included in .gitignore
- โข Example configuration files use placeholder values only
- โข TypeScript implementation with comprehensive testing
Key Features
- ๐ Wallet Management: Create, import, and delete SUI wallets
- ๐ Private Key Handling: Secure retrieval of wallet credentials
- ๐ฐ Balance Checking: Real-time SUI balance queries
- ๐ค Token Transfers: Send SUI to any valid address
- ๐ Slippage Protection: Configurable slippage tolerance for transfers
- ๐งช Comprehensive Testing: 14 test cases covering all functionality
- ๐ก๏ธ Error Handling: Robust validation and error management
- โก TypeScript: Full type safety and modern development practices
Build & Run
Build the Project
npm run build
Note: The README shows "npn run build" but this appears to be a typo - should be "npm run build"
Run the Bot
npm run main
Testing
Run Test Suite
npx vitest run
Test Coverage
The project includes comprehensive testing with 14 test cases:
โ Wallet Management Tests
- โ should create a wallet successfully
- โ should not create a wallet if one already exists
- โ should not import a wallet if one already exists
- โ should get wallet balance
- โ should return public key after wallet is created
- โ should return private key after wallet is created
โ Error Handling Tests
- โ should throw error when trying to get balance with no wallet
- โ should throw error when trying to get private key with no wallet
- โ should throw error when trying to get public key with no wallet
๐ธ Transfer & Slippage Tests
- โ should send SUI to a correct address
- โ should fail to send SUI to an incorrect address
- โ should send SUI within slippage tolerance
- โ should fail to send SUI due to exceeding slippage tolerance
- โ should fail to send SUI due to slippage tolerance (too low)
Bot Commands
Primary Commands
Command | Description |
---|---|
/start | Initialize the bot and display welcome message with available options |
Interactive Bot Buttons
The bot provides interactive buttons for all wallet operations. Users can perform actions by clicking buttons rather than typing commands.
Button | Parameters | Description |
---|---|---|
createWallet | None | Generate a new SUI wallet with public/private key pair |
importWallet | <suiprivkey....> | Import existing wallet using SUI private key |
deleteWallet | <suiprivkey....> | Remove wallet from bot (requires private key confirmation) |
getPrivateKey | None | Retrieve private key of current wallet |
getPublicKey | None | Retrieve public key of current wallet |
checkBalance | None | Display current SUI balance in wallet |
sendSui | <ADDRESS> <AMOUNT> | Send SUI tokens to specified address |
sendSuiSlippage | <ADDRESS> <AMOUNT> <SLIPPAGE> | Send SUI with slippage protection (default: 1%) |
exit | None | Close bot interaction and clear session |
Usage Examples
Example Button Interactions
Import Wallet:
importWallet suiprivkey1qxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Send SUI:
sendSui 0x1234567890abcdef1234567890abcdef12345678 1.5
Send with Slippage:
sendSuiSlippage 0x1234567890abcdef1234567890abcdef12345678 1.5 0.5
Installation & Setup
Prerequisites
- โข Node.js: Version 16 or later
- โข npm: Node package manager
- โข Telegram Bot Token: From @BotFather
- โข SUI Network Access: For blockchain interactions
1. Clone Repository
git clone https://github.com/ecorey/tg_bot.git cd tg_bot
2. Install Dependencies
npm install
3. Configure Environment
# Copy environment template cp .env.example .env # Edit configuration nano .env
Configuration
Environment Variables
# Telegram Bot Configuration TELEGRAM_BOT_TOKEN=your_bot_token_here TELEGRAM_CHAT_ID=your_chat_id_here # SUI Network Configuration SUI_NETWORK=mainnet SUI_RPC_URL=https://sui-mainnet.nodereal.io/v1/your_api_key # Security Settings ENABLE_LOGGING=true MAX_TRANSFER_AMOUNT=100 DEFAULT_SLIPPAGE=1.0
Bot Setup with @BotFather
- 1. Start a chat with @BotFather on Telegram
- 2. Send
/newbot
command - 3. Choose a name and username for your bot
- 4. Copy the provided token to your .env file
- 5. Set bot commands using
/setcommands
Project Structure
tg_bot/ โโโ src/ # Source code โ โโโ bot/ # Bot logic and handlers โ โโโ wallet/ # SUI wallet management โ โโโ utils/ # Utility functions โ โโโ types/ # TypeScript type definitions โโโ tests/ # Test suite (14 test cases) โโโ assets/ # Static assets and resources โโโ package.json # Dependencies and scripts โโโ tsconfig.json # TypeScript configuration โโโ .gitignore # Git ignore rules โโโ README.md # Project documentation
Security Best Practices
๐ก๏ธ Essential Security Measures
- โข Environment Variables: Store all sensitive data in .env files
- โข .gitignore: Prevent committing sensitive configuration files
- โข Input Validation: Validate all user inputs and addresses
- โข Error Handling: Comprehensive error management without exposing sensitive data
- โข Key Management: Secure handling of private keys in memory
- โข Transaction Limits: Implement reasonable transfer limits
- โข Slippage Protection: Default slippage tolerance to prevent MEV attacks
๐ Emergency Response
- 1. Immediate Actions: Stop the bot service immediately
- 2. Rotate Credentials: Generate new bot token from @BotFather
- 3. Review Logs: Check for any suspicious activity
- 4. Update Environment: Refresh all environment variables
- 5. Restart Service: Deploy with new credentials
๐ Ongoing Security Practices
- โข Regular Audits: Review code and dependencies monthly
- โข Dependency Updates: Keep all packages updated
- โข Monitoring: Log all transactions and errors
- โข Testing: Run security tests before deployment
- โข Access Control: Limit bot permissions and user access
Troubleshooting
Common Issues
โข Check TELEGRAM_BOT_TOKEN in environment variables
โข Verify network connectivity to Telegram servers
โข Ensure bot is not already running on another instance
โข Verify SUI network RPC endpoint is accessible
โข Check if wallet already exists for the user
โข Ensure sufficient permissions for file operations
โข Validate recipient address format
โข Check wallet balance before transfer
โข Verify slippage tolerance settings
โข Ensure network connectivity to SUI blockchain
โข Run:
npm run test
to see detailed errorsโข Ensure test environment has proper configuration
โข Check for any missing dependencies
Development Tips
- โข Use
npm run build
to check TypeScript compilation - โข Run tests frequently with
npx vitest run
- โข Monitor console logs for error messages and debugging info
- โข Test with small amounts before larger transfers
- โข Keep backup of wallet private keys in secure location
- โข Use testnet for development and testing phases