Telegram Bot using server wallets
Learn how to create and integrate Telegram bots with Dynamic’s server wallets
Telegram Bot Integration
Telegram bots are fast becoming the go-to interface for crypto apps—used for everything from executing trades to powering automated cross-border remittances. With Dynamic Server Wallets, you can bring secure, wallet infrastructure directly into your Telegram bots to create seamless experiences without browser extensions or wallet popups.
Dynamic Server Wallets run on your backend, allowing bots to sign transactions, manage assets, and interact with smart contracts—all in response to Telegram commands or workflows. This enables a wide range of powerful use cases:
- Stablecoin Remittances: Set up recurring payments to family members by their Telegram usernames, making it easy to automate weekly or monthly transfers without requiring recipients to manage complex wallet addresses.
- Trading Bots: Execute swaps, limit orders, or rebalance strategies via chat commands or automated triggers.
- Portfolio Management: Query wallet balances, track performance, and reallocate assets—all from Telegram.
In this guide, you’ll learn how to create a Telegram bot that uses Dynamic’s server wallets infrastructure to provide wallet functionality to Telegram users. If you want to take a quick look at the final code, check out the GitHub repository.
Dynamic server wallets will work on EVM, SVM and Sui. More chain support coming soon.
This guide uses our new TSS MPC embedded wallets. Learn more about it here.
Overview
This Telegram bot integration allows users to:
- Create EVM-compatible wallets
- Send crypto to other addresses
- Sign messages with their wallet
The implementation uses:
- Dynamic’s server wallets: Creation and handling of wallet & signatures
- Supabase: Stores user wallets linked with Telegram IDs
- Grammy: A framework for building Telegram bots with TypeScript
- Viem: Handles Ethereum blockchain interactions and transaction formatting
Setup
Before starting, you’ll need:
- Dynamic account with environment set up
- Telegram Bot created via BotFather
- Supabase project for database storage
- Bun or Node.js installed
Dynamic Environment Setup
Create a new environment in the Dynamic dashboard. Since TSS MPC wallets are available only in closed alpha, you’ll need to request access to enable it for your environment.
- Navigate to the Dynamic Dashboard > Developers
- Enable “Embedded Wallets” and set the default wallet version to V3
- Go to “SDK and API Keys” under the Developers section
- Copy your
Environment ID
and create a newAPI Token
- you’ll need these to authenticate your requests to Dynamic’s API
Telegram Bot Setup
Go to bothfather on telegram and create a new bot. You’ll receive a token that you’ll use to authenticate your bot.
Copy the Bot token and save it in your .env
file.
Supabase Setup
Head over to Supabase and create a new project. Once your project is set up, create a new table called wallets
with the following schema:
Getting Started
1. Create a New Project
First, set up a new TypeScript project:
Set up your project based on your preferred package manager. Each command below initializes a new project and installs the necessary dependencies:
2. Set Up Project Structure
Create the following project structure:
3. Configure Environment Variables
Create a .env
file with your credentials:
Remember to keep your environment variables secure and never commit them to public repositories.
Implementation
Client Setup
First, let’s set up the Dynamic and Supabase clients:
Wallet Utility Function
Create a utility function to handle wallet creation and retrieval:
Here, we first check if the user already has a wallet associated with their Telegram ID in our database. If they do, we retrieve the wallet details. If not, we create a new wallet for them and store it in the database.
Command Handlers
Now let’s implement the command handlers:
Wallet Command
This is just a simple command that either creates a new wallet or retrieves the existing one for the user using the utility function we just created.
Sign Command
In this command, we use the .signMessage
method from the Dynamic client to sign a message with the user’s wallet. The message that is being signed is passed as a command argument by the user itself.
Send Command
This example uses Base Sepolia, but you can use any chain by swapping out the chain and the RPC URL.
Here, we create a viem client using the .createViemPublicClient
method from the Dynamic client. We prepare a transaction request and sign it using the .signTransaction
method. Finally, we send the signed transaction to the blockchain.
The user provides the recipient address and the amount of ETH to send as command arguments.
Main Bot File
Finally, let’s create the main bot file that brings everything together:
Here, we just configure the bot with the commands we created earlier. The bot will respond to /wallet
, /send
, and /sign
commands.
Running the Bot
To run your Telegram wallet bot:
Make sure to add the appropriate scripts to your package.json
:
Conclusion
You’ve successfully created a Telegram bot that integrates with Dynamic’s server wallets! This bot demonstrates how to bring cryptocurrency features to messaging platforms, making blockchain technology more accessible to everyday users. If you want to take a look at the full source code, check out the GitHub repository.
For additional help or to join the community:
- Join our Slack community
- Check out Dynamic’s documentation
- Follow us on Twitter