
View Source Code
Access the complete source code for this bot on GitHub
Try Live Demo
Interact with the finished bot on Telegram
Prerequisites
Before you begin, ensure you have:- Node.js - v22 or later
- Sim API Key - Get your API key
- Telegram Bot Token - Create one via @BotFather
- Supabase Account - Create a free account
Features
By the end of this guide, your top token holders tracker will:- Identify Top Token Holders - Read a CSV of popular tokens exported from Dune and find their top holders
- Monitor Balance Changes - Set up subscription webhooks to receive real-time balance change notifications for those wallets
- Send Telegram Alerts - Deliver formatted Telegram messages with transaction details
- Manage Subscriptions - Pause, resume, and view your webhook subscriptions
Project Setup
Let’s initialize the project.1
Create Project Directory
2
Install Dependencies
We need Express, the Postgres client, and a CSV parser to handle the Dune export.
3
Set Up Supabase
- Go to supabase.com/dashboard and create a new project
- Once created, go to Project Settings → Database
- Scroll to Connection string and select the URI tab
- Copy the Transaction pooler connection string (uses port
6543)
The Transaction pooler connection is recommended for serverless deployments like Vercel.
4
Set Up Environment Variables
Create a
.env file in your project root:.env
5
Create Configuration
Update your
package.json to enable ES Modules and add a start script:package.json
6
Initialize Server and Database
Create the entry point
index.js. We initialize the database tables on startup.index.js
7
Create Tables and Enable Row Level Security
In your Supabase dashboard, go to SQL Editor and run:This creates three tables:
top_holders for storing token holder data, subscribers for Telegram chat IDs, and webhooks for tracking active subscriptions. The RLS policies allow your server full access while keeping the database secure.Get Top ERC20 Tokens
We need a list of popular tokens to monitor. Create a file calledtokens.csv in your project root with the following content:
tokens.csv
This CSV contains the top WETH and USDC tokens by volume across chains. To verify or explore a larger dataset, see this Dune query.
Load Token Data
We need to read this CSV file and map the blockchain names (e.g., “ethereum”) to their respective Chain IDs (e.g., 1). Add this logic toindex.js:
index.js
Get Top Token Holders
Now we’ll identify the top holder addresses for each token using Sim’s Token Holders API and store them in our database.Fetch Holders for a Token
index.js
Store Top Holder Addresses
This function iterates through the CSV records, fetches top holders, and saves them to the database.index.js
Set Up Webhooks
We’ll use Sim’s Subscriptions API (/beta/) to register webhooks. We use the balances subscription type.
Create a Webhook
index.js
Create Webhooks for All Top Holders
Iterate through ourtop_holders table and create a subscription for each.
index.js
Handle Balance Change Events
When a top holder moves funds, Sim sends a POST request to your webhook URL.Process Incoming Webhooks
Add the/balances route to your Express app.
index.js
Send Telegram Notifications
Manage Subscribers
We use PostgreSQL to persist chat IDs.index.js
Send Messages
index.js
Format Alert Messages
index.js
Handle Telegram Commands
Add the endpoint for Telegram updates.index.js
Manage Webhooks
The Subscriptions API provides endpoints to list and update your webhooks.Pause and Resume
index.js
Deploy and Configure
1
Start Your Server
Run your Express app:
2
Expose to Public Internet
If developing locally, use ngrok to make your localhost accessible:Copy the provided URL (e.g.,
https://abcd-123.ngrok-free.app) and update WEBHOOK_BASE_URL in your .env.3
Register Telegram Webhook
Tell Telegram to send updates to your server:
4
Initialize the Tracker
Since our server is running, we can trigger the setup process using CURL or Postman:
5
Subscribe to Alerts
Open your Telegram bot and send
/start to begin receiving top holder alerts.Conclusion
You’ve built a top token holders tracker bot that monitors large token holders in real-time using Sim’s Subscriptions API. The key components we covered:- Node.js & Express - A lightweight server for handling webhooks and Telegram commands.
- CSV Integration - Parsing Dune Analytics data to drive your bot’s logic.
- Supabase PostgreSQL - Cloud-hosted database for storing top holders and managing subscribers.
- Sim APIs - Using Token Holders and Subscriptions endpoints to power the logic.