Telegram bot for SwiftBridge - enabling crypto offramp/onramp, swaps, and P2P transfers on Base network.
- π± 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
/start- Welcome message/help- Command list/register [username]- Register username/wallet- Get wallet info
/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
/balance- Check balances/rates- Current exchange rates/history- Transaction history
- Node.js v18+
- Telegram Bot Token (from @BotFather)
- Deployed SwiftBridge contracts on Base Sepolia
- Operator wallet with funds
# Install dependencies
npm install
# Copy environment file
cp .env.example .env
# Edit .env with your values
nano .envBOT_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- Open Telegram and search for @BotFather
- Send
/newbot - Follow instructions to create your bot
- Copy the token provided
# Development mode (with hot reload)
npm run dev
# Production build
npm run build
npm startswiftbridge-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
/register
or with custom username:
/register myusername
/buy 50 USDT
/send 25 USDT to @john
/swap 100 USDC to USDT
/rates
- Create command file in
src/commands/ - Import in
src/bot.ts - 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);The bot uses Winston for logging:
- Console output (colored)
error.log- Error logscombined.log- All logs
β οΈ Never commit.envfile- π Store operator private key securely
- π‘οΈ Use environment variables for sensitive data
- π Enable logging for audit trail
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# 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- Check bot token is correct
- Verify bot is running:
pm2 status - Check logs:
tail -f error.log
- Check operator wallet has funds
- Verify contract addresses are correct
- Check RPC URL is working
- Telegram has rate limits for bots
- Implement queuing for high-traffic scenarios
- Fork the repository
- Create feature branch (
git checkout -b feature/amazing-feature) - Commit changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open Pull Request
MIT License - see LICENSE file
- GitHub Issues: Report a bug
- Telegram: @SwiftBridgeSupport
Built with β€οΈ for the Base ecosystem