Create a Solana Telegram Bot in Less Than 100 Lines of Code
Introduction Want to stay updated on Solana events in real-time? This guide will show you how to create a Telegram bot that can track on-chain activities. We'll use an NFT sales tracker as an example, but the template we're building can be easily adapted for other use cases. Here's what our example bot will look like:
This template combines Helius webhooks for real-time Solana data with Cloudflare Workers for serverless hosting. Whether you're tracking NFT sales, monitoring DeFi protocols, or keeping an eye on specific wallets, this setup provides a solid foundation. Setting Up Your Project Let's get your project up and running: 1. Clone the repository: git clone https://github.com/helius-labs/cloudfare-telegram-template.git cd cloudfare-telegram-template 2. Install dependencies: npm install 3. Configure environment variables: Open wrangler.toml and fill in the following keys: - TELEGRAM_BOT_TOKEN: Open Telegram and search for @BotFather.Start a chat with BotFather and send the command /newbot. Follow the prompts to choose a name and username for your bot. Once created, BotFather will give you a token. This is your TELEGRAM_BOT_TOKEN. - TELEGRAM_CHAT_ID: Create a channel and add your bot as an administrator.Send a message to the channel.Visit: https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdatesFind the "chat":{"id": field in the response. This is your TELEGRAM_CHAT_ID. Watch this video for a step-by-step guide: Create a Telegram Bot and Obtain the Chat ID - Step-by-Step Guide - HELIUS_API_KEY: Your Helius API key (get it from Helius) Please be sure not to commit these values to Github. 4. Deploy to Cloudflare: npm run deploy After running this command, you'll see your deployment URL in the console output. Make note of this URL as you'll need it in the next step. 5. Create your webhook: Use the deployment URL from the previous step to create your webhook: curl -X POST https://your-worker-url.workers.dev/create-webhook (Replace your-worker-url with your actual worker URL You'll receive a success response after running this command. You can view the new webhook you've set up on your Helius dashboard at: https://dashboard.helius.dev/webhooks Note: It may take 2-3 minutes for the new webhook to fully spin up and become operational. 6. Edit your webhook: After creating your webhook, you can customize it further in the Helius dashboard: Go tohttps://dashboard.helius.dev/webhooksYou should see your newly created webhook in the list. Click on the webhook to edit its settings.Here you can modify various parameters such as:Transaction types you want to trackSpecific wallet addresses to monitorNetwork (mainnet, devnet)Important: Keep the "Webhook URL" field unchanged. It should still point to your Cloudflare Worker's /webhook endpoint (https://your-worker- url.workers.dev/webhook).
The Code Breakdown First, let's examine our imports and type definitions: import { Hono } from 'hono';
We're using Hono, a lightweight web framework for Cloudflare Workers. The Env type defines our environment variables for Helius and Telegram integrations. Next, we set up our Hono app: const app = new Hono<{ Bindings: Env }>();
app.get('/', (c) => c.text('Solana Action Bot is running!')); This creates our app and sets up a simple health check endpoint. Now, let's create our webhook: app.post('/create-webhook', async (c) => { const webhookURL = `${new URL(c.req.url).origin}/webhook`; console.log('Setting up webhook with URL:', webhookURL);
This endpoint sets up our Helius webhook. In this example, we're tracking NFT sales from the Magic Eden v2 program, but you can modify the transactionTypes and accountAddresses to suit your needs. Here's how we send messages to Telegram: async function sendTelegramMessage(message: string, env: Env) { const url = `https://api.telegram.org/bot${env.TELEGRAM_BOT_TOKEN}/sendMessage`; const response = await fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ chat_id: env.TELEGRAM_CHAT_ID, text: message, parse_mode: 'Markdown', }), }); return response.json(); }
This function formats our message and sends it to our Telegram chat. Finally, let's handle the incoming webhook data: app.post('/webhook', async (c) => { console.log('Webhook endpoint hit'); console.log('Request URL:', c.req.url);
This is where we process the data from Helius and send formatted messages to Telegram. Based on your use case, you can customize this part to handle different types of transactions or extract different information. Customization Options While our example focuses on NFT sales, you can easily adapt this template for various use cases: 1. Modify the transactionTypes in the webhook creation to track different events 2. Change the accountAddresses to monitor specific programs or wallets 3. Adjust the message formatting in the /webhook endpoint to suit your data needs 4. Implement additional logic to filter or process the incoming data Explore the Helius webhooks documentation to discover the full range of trackable data and events. However, don't limit yourself to just the explicitly defined events! Helius webhooks are incredibly versatile and can track a wide array of on-chain activities, even those not directly parsed or mentioned in our documentation. Here are some examples of events you could track: Token transfers for specific SPL tokensNew program deploymentsRaydium pool creations or liquidity additionsGovernance proposal creations or votesMetaplex candy machine launchesSerum market creationsBy leveraging this template, you can create Telegram bots for a wide array of Solana monitoring tasks, from DeFi protocol events to wallet activity tracking and beyond. If you've read this far, thank you! We hope this guide has helped get you started with creating your own Solana Telegram bot 🤖
Market corrections often drive new investors to sell at a loss, with short-term holders being especially sensitive to volatility. The alignment of MVRV and SOPR by Age indicators shows new investors are both underwater and stressed enough to realize losses. This parallel behavior suggests we're at a critical point for short-term Bitcoin holders, potentially signaling a significant market sentiment shift.
🚨A trader was liquidated for $1 million using just 3x leverage, despite it being relatively low.
Many traders who believe Bitcoin will never drop below $60,000 or $50,000 are currently longing at $70,000 with 2x-3x leverage.
Be careful because market is all about stop-loss hunting.
Market is trying to liquidate both sides to move higher and making manipulative profits !
We can see a strong rise to 78-80k range , but before shorts are highly getting created here at this range which would get liquidated at 72-73k with over 1b$ in value !
The Next Billion Gem you are going to miss - $slerf
#slerf was launched through presale stuff , but accidentally developer burnt supply meant for presales and 10m$ liquidity!
He meant to burn the unknown tokens that were sent to presale wallet but accidentally burnt all tokens including slerf &
#SLERF has been listed over 15+ cexs with 1.5b$ volume in less than 24 hours generated on chain !
It hit a new ath of 1.5$ back now & is whooping ready to hit 2-2.5$ range easily !
Many people have donated over thousands of sol for presalers , even Jupiter dex & HTX have announced that they would be donating whole $slerf trading revenue!
That’s a huge , this bull run is going to definitely huge !
Disclaimer:- This post doesn’t means to say anything about buy/sell points of slerf and buying and selling truly depends on you , no one can predict what will happen next , your financial decisions should be your own
Starknet Will Airdrop STRK Tokens on February 20
The total distribution amount exceeds 700 million STRK, and approximately 1.297 million wallets are eligible to claim it, including early users of ecosystem dapps, networks Contributors, Ethereum builders and open source developers.
Criteria: Users who performed more than five transactions in total up to November 15th, 2023, were active for three months or more, transacted with $100 volume or more, and had 0.005 ETH or more in their account on November 15th, 2023, are eligible for Provisions. Note that the program is aimed at excluding Sybil behavior (on which we will expand on further!
#𝗠𝗼𝗱𝗲 𝗡𝗲𝘁𝘄𝗼𝗿𝗸 𝗔𝗶𝗿𝗱𝗿𝗼𝗽 𝗤𝘂𝗲𝘀𝘁 𝗹𝗶𝘃𝗲 Get in on the action with the Mode Network Airdrop Quest!
- Join : https://ref.mode.network/0zgMFS - Connect Twitter/X - Connect your wallet - Bridge ETH from mainnet to Mode (Just Bridge Small amounts like 0.02 ETH for testing ecosystem)
📖𝗪𝗮𝗻𝘁 𝘁𝗼 𝗲𝗮𝗿𝗻 𝗠𝗢𝗥𝗘 𝗽𝗼𝗶𝗻𝘁𝘀 ?
- Engage in DeFi, NFTs, L2s, OG, Degening & yields,Bridge your assets to Mode,Invite friends to Mode,Use ecosystem apps Etc.
— Check out Mode ecosystem and Earn 2x Points - Swap/provide liquidity - Supply/borrow on - Mint Mode domain - Swap Eth/Weth pair 10 times