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 iCopy 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 .envWe 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 /newbotinto the chat, follow the instructions, and copy the bot token. Paste its value into theTELEGRAM_BOT_TOKENvariable in the.envfile.
- 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 /startcommand. Then open to the linkhttps://api.telegram.org/bot<YourBOTToken>/getUpdates, whereYourBotTokenis the token you copied from the BotFather. From thechatobject, copy theidand put it into theTELEGRAM_CHAT_IDvariable in the.envfile. Check this StackOverflow answer for more details.
Use the following command to start the server locally:
bun run src/index.tsYour 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!