Get Telegram notifications for Fan Token transfers

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?

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 required tools installed:

The full project can be found on this GitHub repository.

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):

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:

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.

Step 6: Configure Constants

Create a constants.ts file to store environment variables:

Step 7: Sending Telegram Messages

Install the Axios HTTP client:

Create a helper function in libs/telegram.ts to send messages using Axios:

Step 8: Final Configuration and Running the Indexer

Configure .env File

Edit .env with your Telegram bot credentials:

Create a Telegram Bot

  1. Message @BotFather on Telegram and run:

  2. Follow the prompts to get your bot token.

  3. Add the bot to your Telegram group and run /start.

  4. Visit https://api.telegram.org/bot<YourBOTToken>/getUpdates to find the group chat ID.

Finally, install dependencies and start the indexer

With this setup, you now have an Envio-powered indexer that listens for Fan Token transfers and posts whale alerts to Telegram.

To go further, you can self-host the indexer or deploy it to Envio’s hosted service.

And since we are saving the balances, it can be used as a GraphQL balance API too.

Last updated

Was this helpful?