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

CommandDescription
/startInitialize 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.

ButtonParametersDescription
createWalletNoneGenerate 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)
getPrivateKeyNoneRetrieve private key of current wallet
getPublicKeyNoneRetrieve public key of current wallet
checkBalanceNoneDisplay 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%)
exitNoneClose 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. 1. Start a chat with @BotFather on Telegram
  2. 2. Send /newbot command
  3. 3. Choose a name and username for your bot
  4. 4. Copy the provided token to your .env file
  5. 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. 1. Immediate Actions: Stop the bot service immediately
  2. 2. Rotate Credentials: Generate new bot token from @BotFather
  3. 3. Review Logs: Check for any suspicious activity
  4. 4. Update Environment: Refresh all environment variables
  5. 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

Bot not responding:
โ€ข Check TELEGRAM_BOT_TOKEN in environment variables
โ€ข Verify network connectivity to Telegram servers
โ€ข Ensure bot is not already running on another instance
Wallet creation fails:
โ€ข Verify SUI network RPC endpoint is accessible
โ€ข Check if wallet already exists for the user
โ€ข Ensure sufficient permissions for file operations
Transfer failures:
โ€ข Validate recipient address format
โ€ข Check wallet balance before transfer
โ€ข Verify slippage tolerance settings
โ€ข Ensure network connectivity to SUI blockchain
Test failures:
โ€ข 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