DEV Community

Apollo
Apollo

Posted on

I Sniped a Solana Token in 400ms — Here's the Full Tech Stack

I Sniped a Solana Token in 400ms — Here's the Full Tech Stack

Sniping a newly launched Solana token is equal parts exhilarating and technical. It requires precision, speed, and carefully engineered infrastructure. Last week, I successfully sniped a token in just 400 milliseconds. Here's a deep dive into the tools, techniques, and stack that made it possible.


The Anatomy of a Snipe

Sniping a token involves executing a buy transaction immediately after a token's liquidity pool (LP) is created on a decentralized exchange (DEX) like Raydium. The goal is to be the first to purchase the token before others, benefiting from the lowest possible price. To achieve this, you need:

  • Ultra-low latency between detecting the LP creation and executing the transaction.
  • Optimized MEV (Maximal Extractable Value) strategies.
  • Reliable RPC connections and efficient transaction routing.

Here’s how I did it.


Tech Stack Overview

  1. Jito Labs for MEV Bundles: Jito’s MEV framework allowed me to bundle transactions and prioritize my snipe.
  2. Jupiter Routing for Optimal Swap Paths: Jupiter’s API ensured I was using the most efficient swap route for the token.
  3. Helius RPC for Speed and Reliability: Helius’s RPC endpoints provided the low-latency connection needed for rapid execution.

Step 1: Detecting the LP Creation

The first step is detecting when a new liquidity pool is created. For this, I used Helius’s WebSocket API to listen for Program Log events related to the Raydium program. Here’s the code snippet I used to monitor LP creations:

const { Connection } = require("@solana/web3.js");
const wsUrl = "wss://helius-rpc.com/ws";
const connection = new Connection(wsUrl);

connection.onProgramAccountChange(
  new PublicKey("RaydiumProgramId"),
  (accountInfo) => {
    const logs = accountInfo.logs;
    if (logs.includes("LiquidityPoolCreated")) {
      console.log("New LP detected!");
      snipeToken(accountInfo.tokenMint);
    }
  }
);
Enter fullscreen mode Exit fullscreen mode

This WebSocket connection listens for LiquidityPoolCreated logs emitted by the Raydium program. When detected, it triggers the snipe function.


Step 2: Building the Snipe Transaction

Once an LP is detected, I constructed the transaction using Jupiter’s Swap API to ensure the most efficient swap path. Here’s how I fetched the swap route:

import axios from "axios";

async function getSwapRoute(tokenMint) {
  const response = await axios.get("https://quote-api.jup.ag/v1/quote", {
    params: {
      inputMint: "SOL",
      outputMint: tokenMint,
      amount: 1, // Amount of SOL to swap
      slippage: 1, // 1% slippage tolerance
    },
  });
  return response.data;
}
Enter fullscreen mode Exit fullscreen mode

The API returns the optimal route and instructions for the swap. I then encoded these instructions into a transaction.


Step 3: Submitting the Transaction with Jito MEV

To ensure my transaction was prioritized, I used Jito’s MEV bundle feature. Bundles allow you to group transactions and submit them in batches, increasing the chance of front-running competing snipers. Here’s how I formatted the bundle:

const { Bundle, JitoClient } = require("@jito-labs/web3");

const jitoClient = new JitoClient("https://jito-rpc.com");

async function sendSnipeBundle(swapTransaction) {
  const bundle = new Bundle([swapTransaction]);
  await jitoClient.sendBundle(bundle);
}
Enter fullscreen mode Exit fullscreen mode

Jito’s bundling ensured my transaction was processed ahead of others, minimizing the risk of being sandwiched.


Step 4: Optimizing Latency with Helius RPC

Speed is critical in sniping. I relied on Helius’s dedicated RPC endpoints to minimize latency. With an average response time of 50ms, Helius ensured my transactions were submitted almost instantly. Here’s how I configured the connection:

const { Connection } = require("@solana/web3.js");
const heliusRpc = "https://helius-rpc.com";
const connection = new Connection(heliusRpc, {
  commitment: "confirmed",
});
Enter fullscreen mode Exit fullscreen mode

Helius’s global infrastructure and optimized endpoints were crucial in achieving the 400ms snipe time.


Lessons Learned

  1. Pre-Warm Your Connections: Always pre-warm your RPC and API connections to reduce initialization time.
  2. Monitor Gas Fees: Even on Solana, transaction prioritization can impact execution speed. Use Jito bundles to ensure your transactions are prioritized.
  3. Test Your Stack: I spent weeks testing my setup on testnet to fine-tune latency and ensure reliability.

Conclusion

Sniping a Solana token in 400ms is no small feat, but with the right tools and optimizations, it’s achievable. Leveraging Jito’s MEV bundles, Jupiter’s routing, and Helius’s RPC endpoints made the difference between success and failure. If you’re diving into Solana sniping, focus on optimizing latency, transaction prioritization, and reliable infrastructure.

Happy sniping!


🚀 Try It Yourself & Get Airdropped

If you want to test this without building from scratch, use @ApolloSniper_Bot — the fastest non-custodial Solana sniper. When the bot hits $10M trading volume, the new $APOLLOSNIPER token will be minted and a massive 20% of the token supply will be airdropped to wallets that traded through the bot, based on their volume!

Join the revolution today.

Top comments (0)