🏟️ BUIDL where legends play. Join our Hackathon at Parc des Princes, Paris – July 2025 •
Register Now
Chiliz Chain Developer Docs
Chiliz ChainBlock ExplorerCommunitySocios.com
English
English
  • Chiliz Chain developer docs
  • Quick Start
    • Chiliz Chain in a nutshell
    • Connect to Mainnet and Testnet
    • Deploy and verify a contract
      • Deploy with Remix IDE
      • Deploy with thirdweb
      • Verify with Chiliscan
      • Verify with Chiliz Block Explorer
    • Run a Chiliz Chain Node
    • Free online courses
    • Inflation Supply Allocation Addresses
    • Smart Contract Addresses
  • Learn
    • About Chiliz Chain
      • Tokenomics
      • Security Audits
      • Chiliz Labs
    • About Wallets
      • How to use MetaMask
        • Install MetaMask
        • Link Chiliz Chain to MetaMask
      • How to use a multisig wallet (Safe)
    • About Bridging
      • Using Dcentralab's Chainport
      • Using Chiliz Bridge
      • Bridging stablecoins
      • Making your project token bridgeable
    • About Staking
      • Stake your CHZ
      • Unstake your CHZ
      • Staking Rewards
      • Stake CHZ from your Ledger
      • Chiliz Staking FAQ
    • About Validators
      • Defining Validators and Delegators
      • Why Become a Validator
      • How to Become a Validator
      • Running a Validator node
      • How to Stop Being a Validator
      • About Validator slashing
    • About Fan Tokens
      • 2023 Migration of Fan Tokens to Chiliz Chain
    • About Stablecoins
      • Stablecoins on Chiliz Chain
    • Glossary
      • Blockchain
      • Consensus mechanisms
      • Governance
      • Validator
      • Staking
      • Wallet
      • CAP-20
      • Wrapped CHZ (wCHZ)
  • Develop
    • Basics
      • Connect to Chiliz Chain
        • Connect using RPC
        • Run a Chiliz Chain Node
        • Use a hardware wallet
      • Block Explorers
      • Testnet Faucet
        • Obtain testCHZs with Tatum Faucet
      • Use Wrapped CHZ
      • How-Tos
        • How to get the balance of a wallet
        • How to get the history of a wallet
        • How to get the metadata of a specific NFT
      • Tips & Tricks
    • Advanced
      • How to integrate Socios Wallet in your dApp
      • How to use Account Abstraction
      • How to get the USD price of Fan Tokens
      • How to generate random numbers
      • How to follow transfers of a Fan Token
      • How to create Telegram notifications for Fan Token transfers
      • How to estimate gas fees
    • Chiliz Chain API
    • Developers FAQ
  • Community
    • Chiliz Chain Ecosystem
      • Developer Tools
        • Ankr
        • Azuro
        • Biconomy
        • Blocknative
        • Hyperlane
        • Lumx
        • Moralis
        • Pyth
        • Reown
        • Rarible
        • Tatum
        • The Graph
        • Thirdweb
        • Web3Auth
      • Custody solutions
        • Cobo
        • Fireblocks
      • Wallets
        • Magic
        • Privy
    • Developers events
      • Chiliz Sports Hackathon - July 2024
        • Setting The Stage
        • Getting Started
        • Mission Brief & Key Dates
        • The Prize Money
        • Theme & Intro
        • Tracks, Requirements, Regulations & Scoring Criteria
        • The Process
        • Disclaimers
        • Useful information
      • ETHGlobal Bangkok Hackathon 2024
      • ETHGlobal Istanbul Hackathon 2023
      • ETHGlobal London Hackathon 2024
      • ETHGlobal Online Hackathon Summer 2024
      • Hacking Poland 2025
      • Lumx Hack powered by ETH Rio
  • Chiliz Chain Changelog
    • Governance Proposals & Decisions
      • February 2025: New validator proposals
      • December 2024: Governance Update Proposals
      • May 2024: Dragon 8 (Tokenomics 2.0) Proposal
      • 2024 Dragon8 hard fork announcement
    • Blockchain code changes
    • Outage reports
      • Details on the May 21st outage
  • Doc Updates
Powered by GitBook
On this page
  • How to do it using Envio?
  • Step 1: Install Prerequisites
  • Step 2: Initialize Envio Indexer
  • Step 3: Configure config.yaml
  • Step 4: Simplify the GraphQL Schema
  • Step 5: Implement Telegram Notification Logic
  • Step 6: Configure Constants
  • Step 7: Sending Telegram Messages
  • Step 8: Final Configuration and Running the Indexer

Was this helpful?

  1. Develop
  2. Advanced

How to create Telegram notifications for Fan Token transfers

Last updated 2 months ago

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:

export const EXPLORER_URL_MONAD = process.env.ENVIO_EXPLORER_URL_MONAD;
export const WHALE_THRESHOLD: string = process.env.ENVIO_WHALE_THRESHOLD ?? "1000";
export const BOT_TOKEN = process.env.ENVIO_BOT_TOKEN;
export const CHANNEL_ID = process.env.ENVIO_TELEGRAM_CHANNEL_ID;
export const MESSAGE_THREAD_ID = process.env.ENVIO_TELEGRAM_MESSAGE_THREAD_ID;

export const explorerUrlAddress = (address: string) =>
  EXPLORER_URL_MONAD + "address/" + address;
export const explorerUrlTx = (txHash: string) =>
  EXPLORER_URL_MONAD + "tx/" + txHash;

Step 7: Sending Telegram Messages

pnpm i axios

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

import axios from "axios";
import { CHANNEL_ID, MESSAGE_THREAD_ID, BOT_TOKEN } from "../constants";

export const sendMessageToTelegram = async (message: string): Promise<void> => {
  try {
    const apiUrl = `https://api.telegram.org/bot${BOT_TOKEN}/sendMessage`;
    await axios.post(apiUrl, {
      chat_id: CHANNEL_ID,
      text: message,
      parse_mode: "HTML",
    });
  } catch (error) {
    console.error("Error sending message:", error);
  }
};

Step 8: Final Configuration and Running the Indexer

Configure .env File

cp .env.example .env

Edit .env with your Telegram bot credentials:

ENVIO_BOT_TOKEN=
ENVIO_TELEGRAM_CHANNEL_ID=
ENVIO_TELEGRAM_MESSAGE_THREAD_ID=
ENVIO_EXPLORER_URL="https://chiliscan.com/"
ENVIO_WHALE_THRESHOLD=1000

Create a Telegram Bot

  1. Message @BotFather on Telegram and run:

    /newbot
  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.

If you created the new group with the bot and you only get {"ok":true,"result":[]}, remove and add the bot again to the group.

Finally, install dependencies and start the indexer

pnpm i
pnpm envio dev

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.

The sample /libs/ folder can be found , including the helpers.ts and ens.ts files.

Install the :

Envio
required tools
pnpm
Node.js
Docker
on this GitHub repository
right here on GitHub
Axios HTTP client