Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
5.7 KiB
Online Wallet Bot
A self-hosted Telegram bot for managing Bitcoin wallets using Electrum. Designed for watch-only (xpub) wallets with air-gapped signing support.
Features
- Per-user isolated wallets
- Watch-only wallet restore from xpub
- Balance display (Confirmed / Unconfirmed)
- Receive address generation
- Unsigned transaction (PSBT) creation with fee options
- Unit switching: BTC / mBTC / sats
- Persian (Farsi) and English language support
- Persistent bottom keyboard
- Optional Tor support (connect via .onion to a public server or your own node)
Prerequisites
- A Linux server with Docker and Docker Compose installed
- A Telegram bot token (from @BotFather)
- Your Telegram user ID (from @userinfobot)
Server Setup (Step by Step)
1. Clone the repository
git clone https://git.goyban.com/goyban/telegtrum_bot.git
cd telegtrum_bot
2. Create your .env file
cp .env.example .env
nano .env
Fill in:
ELECTRUM_VERSION=4.7.2
TELEGRAM_BOT_TOKEN=your_bot_token_here
3. Add your Telegram user ID to the allowed users list
nano allowed_users.txt
Add a line in the format userid, Name:
123456789, Alice
You can find your user ID by messaging @userinfobot on Telegram.
4. Build and start the container
docker compose up -d --build
This will:
- Build the Docker image with Electrum installed
- Start the Electrum daemon
- Launch the Telegram bot
5. Check logs
docker compose logs -f
You should see Electrum daemon started. Launching bot... followed by the bot starting up.
Tor Mode
Tor mode runs Electrum through the Tor network. It uses a separate Docker Compose file and Dockerfile so the standard setup is not affected.
Setup
cp .env.tor.example .env
nano .env
Fill in TELEGRAM_BOT_TOKEN and choose a connection mode:
Option A — your own Electrum server over Tor:
ELECTRUM_SERVER=yournode123.onion:50001:t
Option B — public .onion server (default, no extra config needed):
Leave ELECTRUM_SERVER unset. The bot will connect to electrums3lojbuj.onion:50001:t by default. Override with ELECTRUM_ONION_SERVER if needed.
Start
docker compose -f docker-compose.tor.yml up -d --build
Notes
- Tor runs inside the same container — no sidecar needed.
- The container waits for the Tor SOCKS proxy to be ready before starting Electrum.
- Wallet data is stored in a separate volume (
electrum-tor-data) so it does not mix with the standard setup. tin the server string means TCP — encryption is handled by the Tor layer, not SSL.
Updating the Bot
The bot.py file is mounted as a volume, so you can update it without rebuilding the image:
# Edit bot.py, then:
docker compose restart
# or for Tor mode:
docker compose -f docker-compose.tor.yml restart
To update Electrum itself or system packages:
docker compose up -d --build
# or for Tor mode:
docker compose -f docker-compose.tor.yml up -d --build
Adding or Removing Allowed Users
Edit allowed_users.txt and restart:
nano allowed_users.txt
docker compose restart
Data Persistence
Wallet data is stored in a named Docker volume at /root/.electrum inside the container. This persists across restarts and rebuilds.
| Mode | Volume name |
|---|---|
| Standard | electrum-data |
| Tor | electrum-tor-data |
To back up wallet data (standard mode):
docker run --rm -v electrum-data:/data -v $(pwd):/backup debian:bookworm-slim \
tar czf /backup/electrum-backup.tar.gz -C /data .
Bot Usage Guide
Starting the bot
Open the bot in Telegram and send any message. You'll see a persistent keyboard at the bottom with all available actions.
Add Wallet
Import a watch-only wallet from an xpub (extended public key):
- Press Add Wallet
- Enter a wallet name
- Paste your xpub
- Set a password (min 8 chars, must include upper, lower, and digit)
List
Shows all your wallets.
Load
Load a wallet to make it active:
- Press Load
- Select a wallet (auto-selects if you only have one)
- Enter the wallet password
Balance
Shows the confirmed and unconfirmed balance of the loaded wallet.
Use the inline buttons below the balance to switch between BTC, mBTC, and sats.
Receive
Shows a fresh receiving address for the loaded wallet.
Send
Creates an unsigned transaction (PSBT) for air-gapped signing:
- Press Send
- Choose a fee source: Electrum (recommended) or mempool.space (live)
- Enter fee rate in sat/vB
- Enter the wallet password
- Enter the recipient address
- Enter the amount (in your selected unit)
- Receive the unsigned TX as both a code block and a
.txtfile for offline signing - Sign it with your offline wallet, then use Broadcast
Close
Unloads the active wallet from the Electrum daemon.
Language
Press 🌐 Language to switch between English and Persian (Farsi).
Troubleshooting
Bot not responding: Check logs with docker compose logs -f. Make sure your bot token is correct and the container is running.
"You are not authorized": Your Telegram user ID is not in allowed_users.txt. Add it and restart.
Wallet not loaded error: Use Load before checking balance, receiving, or sending.
Daemon not starting: The container removes the lockfile on startup automatically. If issues persist, try docker compose restart.
Tor mode — Electrum not connecting: Tor bootstrap can take up to ~30 seconds on first run. Check logs with docker compose -f docker-compose.tor.yml logs -f.