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 !
3 Reasons Bitcoin & Altcoins Dumped ๐๐ป ย 1) Tax Selling ย Yesterday, Morgan Stanley reported that there was $256B in capital gains tax selling. ย This was the reason behind the stock market dump, and because crypto is still correlated to it, #BTCย and alts dumped even harder. ย 2) War escalationย ย The war between #Iran & #Israel has escalated quickly.ย ย During these times, people always look to HOLD hard money. ย BTC still hasn't got that status (high volatility and a less established history), so it dumped and alts bleed even more than that.ย ย 3) BTC dominance going up ย Yesterday's altcoin crash pushed BTC dominance to a 3-yr high. ย BTC dumped 5%โ7%, but large caps dumped 15%โ20%. ย What's next for the market? ย Right now, the best way to predict upcoming market movement is to look at the #GOLD chart.ย ย Usually, Gold pumps during these war situations, similar to what happened in Feb 2022. ย If Gold starts going sideways or down, this could be a sign that the war situation is over. ย I'll keep a close eye on this and will continue to update you all.
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!
$DYM 93% Of Total DYM Supply Is Not Staked ๐จโ ย Since yesterday, there has been data circulating around #DYM supply scarcity. ย People are reporting that 93% of its supply is staked, which is causing FOMO among retail investors. ย The reality is that all the unlocked $DYM tokens are also counted towards staked tokens. ย Right now, only 14.6% of DYM's total supply is circulating, which means that 85.4% of its supply is still unlocked. ย This 85.4% of the supply is also counted towards the staked tokens, which makes the staking number look big. ย In reality, only 76M DYM tokens are staked, which represents 52% of the circulating supply and 7.6% of the total supply. ย So, don't FOMO before verifying the data.
#๐ ๐ผ๐ฑ๐ฒ ๐ก๐ฒ๐๐๐ผ๐ฟ๐ธ ๐๐ถ๐ฟ๐ฑ๐ฟ๐ผ๐ฝ ๐ค๐๐ฒ๐๐ ๐น๐ถ๐๐ฒ 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)