Note
You can jump to the Loop Decoder Documentation to read the entire tutorial in one place.
Learn how to create a Telegram bot that sends human-readable alerts about transactions happening on-chain. You can customize this bot for any EVM-compatible blockchain, and you don't need any specific knowledge about EVM transaction decoding and interpretation.
- An installed Bun (see installation guide here)
- An Alchemy account (sign up here)
- An Etherscan account (sign up here)
- A Telegram account
Clone the Bot repository from GitHub and install project dependecies:
git clone https://github.com/3loop/example-tg-bot
cd example-tg-bot
bun i
Copy and rename the .env.example
file to .env
, then paste the Alchemy and Etherescan API keys into the ALCHEMY_API_KEY
and ETHERSCAN_API_KEY
variables.
cp .env.example .env
vim .env
We use the Alchemy API key to monitor new transactions happening on the blockchain, and the Etherscan API key (from the free plan) to fetch contract ABIs and avoid hitting rate limits. The Etherscan API could be optional if the transactions you are interested in do not interact with many contracts, but since we are testing AAVE V3 it will have many interactions.
- Obtain a bot token: Start a chat with the BotFather bot in Telegram, write
/newbot
into the chat, follow the instructions, and copy the bot token. Paste its value into theTELEGRAM_BOT_TOKEN
variable in the.env
file. - Obtain a chat ID: Get the chat ID of the chat where the bot should send notifications. Start a chat with your bot by pressing the
/start
command. Then open to the linkhttps://api.telegram.org/bot<YourBOTToken>/getUpdates
, whereYourBotToken
is the token you copied from the BotFather. From thechat
object, copy theid
and put it into theTELEGRAM_CHAT_ID
variable in the.env
file. Check this StackOverflow answer for more details.
Use the following command to start the server locally:
bun run src/index.ts
Your Telegram bot is now set up and will monitor blockchain transactions and send alerts to the specified chat or channel.
The guide describes all components of the bot and how to modify it to monitor the different EVM contacts.
Let us know on X/Twitter (@3loop_io) if you encounter any problems or have any questions, we'd love to help you!
Happy coding!