Skip to content

SwiftBridge/swiftbridge-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

SwiftBridge Bot

Telegram bot for SwiftBridge - enabling crypto offramp/onramp, swaps, and P2P transfers on Base network.

Features

  • πŸ’± Buy/Sell Crypto - Trade between Naira and crypto
  • πŸ”„ Token Swaps - Exchange tokens via Uniswap V3
  • πŸ“€ P2P Transfers - Send crypto to Telegram usernames
  • πŸ’° Balance Checking - View all token balances
  • πŸ“Š Live Rates - Real-time exchange rates
  • πŸ‘€ Username Registration - Map Telegram username to wallet

Commands

Basic

  • /start - Welcome message
  • /help - Command list
  • /register [username] - Register username
  • /wallet - Get wallet info

Trading

  • /buy <amount> <token> - Buy crypto with Naira
  • /sell <amount> <token> - Sell crypto for Naira
  • /swap <amount> <from> to <to> - Swap tokens
  • /send <amount> <token> to @username - Send to friend

Info

  • /balance - Check balances
  • /rates - Current exchange rates
  • /history - Transaction history

Setup

Prerequisites

  • Node.js v18+
  • Telegram Bot Token (from @BotFather)
  • Deployed SwiftBridge contracts on Base Sepolia
  • Operator wallet with funds

Installation

# Install dependencies
npm install

# Copy environment file
cp .env.example .env

# Edit .env with your values
nano .env

Environment Variables

BOT_TOKEN=your_telegram_bot_token
RPC_URL=https://sepolia.base.org
OPERATOR_PRIVATE_KEY=your_private_key

USER_REGISTRY_ADDRESS=0xFaaE04873914c0102B3c1aA5BCE05C51d0BD3667
ESCROW_MANAGER_ADDRESS=0xBd5287110A78d32A5435E97449BBA408E4F52568
P2P_TRANSFER_ADDRESS=0x2B1160DCAAbFBC21508629425901c809Db923774
SWAP_ROUTER_ADDRESS=0xb71A9C877B0C5CFee262E6039be2439964E0DCdf

Getting a Bot Token

  1. Open Telegram and search for @BotFather
  2. Send /newbot
  3. Follow instructions to create your bot
  4. Copy the token provided

Running

# Development mode (with hot reload)
npm run dev

# Production build
npm run build
npm start

Project Structure

swiftbridge-bot/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ bot.ts              # Main bot file
β”‚   β”œβ”€β”€ config/
β”‚   β”‚   β”œβ”€β”€ contracts.ts    # Contract ABIs & addresses
β”‚   β”‚   └── env.ts          # Environment config
β”‚   β”œβ”€β”€ commands/
β”‚   β”‚   β”œβ”€β”€ start.ts        # /start & /help
β”‚   β”‚   β”œβ”€β”€ register.ts     # /register
β”‚   β”‚   β”œβ”€β”€ balance.ts      # /balance
β”‚   β”‚   β”œβ”€β”€ rates.ts        # /rates
β”‚   β”‚   └── send.ts         # /send
β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”œβ”€β”€ blockchain.ts   # Blockchain interactions
β”‚   β”‚   └── rates.ts        # Exchange rate service
β”‚   └── utils/
β”‚       β”œβ”€β”€ logger.ts       # Logging
β”‚       └── helpers.ts      # Helper functions
└── package.json

Usage Examples

Register Username

/register

or with custom username:

/register myusername

Buy Crypto

/buy 50 USDT

Send to Friend

/send 25 USDT to @john

Swap Tokens

/swap 100 USDC to USDT

Check Rates

/rates

Development

Adding New Commands

  1. Create command file in src/commands/
  2. Import in src/bot.ts
  3. Register command handler

Example:

// src/commands/mycommand.ts
export async function myCommand(ctx: CommandContext<Context>) {
  await ctx.reply('Hello!');
}

// src/bot.ts
import { myCommand } from './commands/mycommand';
bot.command('mycommand', myCommand);

Logging

The bot uses Winston for logging:

  • Console output (colored)
  • error.log - Error logs
  • combined.log - All logs

Security

  • ⚠️ Never commit .env file
  • πŸ” Store operator private key securely
  • πŸ›‘οΈ Use environment variables for sensitive data
  • πŸ“ Enable logging for audit trail

Deployment

Heroku

heroku create swiftbridge-bot
heroku config:set BOT_TOKEN=your_token
heroku config:set OPERATOR_PRIVATE_KEY=your_key
# ... set other env vars
git push heroku main

VPS (Ubuntu)

# Install Node.js
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install -y nodejs

# Clone and setup
git clone your-repo
cd swiftbridge-bot
npm install
npm run build

# Run with PM2
npm install -g pm2
pm2 start dist/bot.js --name swiftbridge-bot
pm2 save
pm2 startup

Troubleshooting

Bot not responding

  • Check bot token is correct
  • Verify bot is running: pm2 status
  • Check logs: tail -f error.log

Transaction failures

  • Check operator wallet has funds
  • Verify contract addresses are correct
  • Check RPC URL is working

Rate limit errors

  • Telegram has rate limits for bots
  • Implement queuing for high-traffic scenarios

Contributing

  1. Fork the repository
  2. Create feature branch (git checkout -b feature/amazing-feature)
  3. Commit changes (git commit -m 'Add amazing feature')
  4. Push to branch (git push origin feature/amazing-feature)
  5. Open Pull Request

License

MIT License - see LICENSE file

Support


Built with ❀️ for the Base ecosystem

About

telegram bot integration

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •