How to create Telegram notifications for Fan Token transfers
Last updated
Was this helpful?
Monitoring the Fan Token™ transfers that happen on Chiliz Chain is a great way to stay informed about high-value moves and keep your community in the loop.
With a bit of configuration and code, you can set up a Telegram bot to notify a group whenever a Fan Token™ transfer surpasses a certain threshold.
How to do it using Envio?
is a powerful indexing tool that allows developers to listen for smart contract events on Chiliz and perform an action based on the event.
In this how-to, you’ll see how to configure the bot, capture the relevant events, and automatically trigger Telegram alerts, thus turning your setup into a “whale watcher” for major transfers.
Step 1: Install Prerequisites
Before we begin, ensure you have the installed:
The full project can be found .
Step 2: Initialize Envio Indexer
Run the following command to initialize an Envio indexer and follow the prompts to generate an ERC20 template on Chiliz Chain (which is an EVM-compatible blockchain):
pnpx envio init
Here are the various selections you should make when prompted:
Step 3: Configure config.yaml
Modify the config.yaml file to specify the contract address of the FC Barcelona Fan Token™ (or any other Fan Token™ you want to track):
# yaml-language-server: $schema=./node_modules/envio/evm.schema.json
name: fan-token-watcher
description: A simple indexer for Fan Tokens that posts notifications to Telegram on large transfers
networks:
- id: 8888 # Chiliz
start_block: 0
contracts:
- name: ERC20
address: "0xFD3C73b3B09D418841dd6Aff341b2d6e3abA433b" # FC Barcelona
handler: src/EventHandlers.ts
events:
- event: "Transfer(address indexed from, address indexed to, uint256 value)"
field_selection:
transaction_fields:
- "hash"
Note: We remove the approval event as we are only interested in transfers.
Step 4: Simplify the GraphQL Schema
Modify the schema.graphql file to track only account balances:
type Account {
id: ID! # Address of the account
balance: BigInt! # Account balance of tokens
}
At this point, we have an ERC20 indexer that listens for events.
Now, let’s add logic to post Telegram notifications.
Step 5: Implement Telegram Notification Logic
Modify the /src/EventHandlers.ts file to include logic for detecting large transfers and sending Telegram alerts.
import { ERC20 } from "generated";
import { isIndexingAtHead, indexBalances } from "./libs/helpers";
import { fetchEnsHandle } from "./libs/ens";
import { sendMessageToTelegram } from "./libs/telegram";
import { WHALE_THRESHOLD, explorerUrlAddress, explorerUrlTx } from "./constants";
ERC20.Transfer.handler(async ({ event, context }) => {
if (isIndexingAtHead(event.block.timestamp) && event.params.value >= BigInt(WHALE_THRESHOLD)) {
const ensHandleOrFromAddress = await fetchEnsHandle(event.params.from);
const ensHandleOrToAddress = await fetchEnsHandle(event.params.to);
const msg = `FC Barcelona WHALE ALERT 🐋: A new transfer has been made by <a href="${explorerUrlAddress(
event.params.from
)}">${ensHandleOrFromAddress}</a> to <a href="${explorerUrlAddress(
event.params.to
)}">${ensHandleOrToAddress}</a> for ${event.params.value} FC Barcelona! 🔥 - <a href="${explorerUrlTx(
event.transaction.hash
)}">transaction</a>`;
await sendMessageToTelegram(msg);
}
await indexBalances(context, event);
});
Step 6: Configure Constants
Create a constants.ts file to store environment variables: