1 min read
In this video, we will create a Telegram bot to get real-time blockchain notifications in Telegram with the help of Node.js and QuickAlerts.
Subscribe to our YouTube channel for more videos!Subscribe
The following code example includes the QuickAlerts expression for MAYC Transfers.
Expression
1tx_logs_address == '0x60E4d786628Fea6478F785A6d7e704777c86a7c6'2&&3tx_logs_topic0 == '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'
Following is the code sample shown in the video. You can also access the file on GitHub.
require("dotenv").config();
const express = require("express");
const TelegramBot = require("node-telegram-bot-api");
const {TOKEN, PORT} = process.env;
const bot = new TelegramBot(TOKEN);
const app = express();
app.use(express.json());
// We are receiving updates at the route below!
app.post('/webhook', async (req, res) => {
const webhook = req.body;
const from = webhook[0].from;
const to = webhook[0].to;
const token_id = Number.parseInt(webhook[0].logs[0].topics[3],16);
const tx_hash = webhook[0].logs[0].transactionHash;
res.sendStatus(200);
const chatId = <TELEGRAM_CHANNEL_ID>;
// Sends text to the above chatID
bot.sendMessage(chatId,
`🔔Bomber Man # ${token_id} transferred🔔\n\n From: ${from}\n\n To: ${to}\n
https://polygonscan.com/tx/${tx_hash}`
);
});
// Start Express Server
app.listen(PORT, () => {
console.log(`Express server is listening`);
});
We ❤️ Feedback!
Let us know if you have any feedback or requests for new topics. We'd love to hear from you.