Crypto Bots

Token Sniping Bot: How to Buy New Crypto Launches in the First Block

Token sniping bots buy new token launches in the first seconds after liquidity is added. Learn how snipers work on Ethereum, BSC, and Solana โ€” and how to build one safely.

A
AI Agents Hubยท2026-03-20ยท4 min readยท772 words

Builder of AI agents, crypto trading bots, and open-source automation tools. Sharing practical guides on how to build, deploy, and profit from AI and DeFi technology.

What Is Token Sniping?

A token sniping bot monitors blockchain mempools and DEX factory contracts for new liquidity pool additions. The moment new liquidity is detected, the bot submits a buy transaction โ€” often within the same block as the liquidity addition.

Why it works: When a new token launches, early buyers get the lowest possible price before price discovery pushes it up. Successful snipers can 2-10x their investment within minutes.

The risk: Most new token launches on BSC and Ethereum are either rugs (liquidity pulled immediately) or honeypots (can't sell). Sniping bots win big on the rare legitimate launches and lose on the many scams.

How Snipers Detect New Launches

Method 1: PairCreated Event (Uniswap/Pancakeswap)

import { ethers } from 'ethers'

const UNISWAP_V2_FACTORY = '0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f'
const PAIR_CREATED_TOPIC = ethers.id('PairCreated(address,address,address,uint256)')

const provider = new ethers.WebSocketProvider(process.env.WS_RPC!)

provider.on({ address: UNISWAP_V2_FACTORY, topics: [PAIR_CREATED_TOPIC] }, async (log) => {
  const iface = new ethers.Interface([
    'event PairCreated(address indexed token0, address indexed token1, address pair, uint)'
  ])
  const parsed = iface.parseLog(log)
  const { token0, token1, pair } = parsed!.args
  
  // Check which token is the "new" one (not WETH/USDC)
  const WETH = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'
  const newToken = token0 === WETH ? token1 : token0
  
  console.log(`New pair detected: ${pair}`)
  console.log(`New token: ${newToken}`)
  
  await evaluateAndSnipe(newToken, pair)
})

Method 2: Pending Transaction Monitoring

Some bots monitor the mempool for addLiquidity calls before they're confirmed:

provider.on('pending', async (txHash) => {
  const tx = await provider.getTransaction(txHash)
  if (!tx) return
  
  // Check if this is an addLiquidity call to Uniswap router
  const ADD_LIQUIDITY_SELECTOR = '0xe8e33700'
  if (tx.to === UNISWAP_V2_ROUTER && tx.data.startsWith(ADD_LIQUIDITY_SELECTOR)) {
    console.log('Liquidity being added! Preparing snipe...')
    // Submit snipe with higher gas to front-run
  }
})

Safety Checks Before Sniping

Blind sniping loses money 90% of the time. Always run these checks:

interface TokenSafetyCheck {
  isHoneypot: boolean
  hasLiquidityLock: boolean
  ownershipRenounced: boolean
  buyTax: number
  sellTax: number
  maxWalletPercent: number
}

async function safetyCheck(tokenAddress: string): Promise<TokenSafetyCheck> {
  // Use honeypot.is API
  const honeypotCheck = await fetch(
    `https://api.honeypot.is/v2/IsHoneypot?address=${tokenAddress}&chainID=1`
  ).then(r => r.json())
  
  // Check contract on Etherscan for source verification
  const isVerified = await checkEtherscanVerification(tokenAddress)
  
  // Simulate buy and sell to detect tax
  const { buyTax, sellTax } = await simulateSwap(tokenAddress)
  
  return {
    isHoneypot: honeypotCheck.honeypotResult?.isHoneypot ?? true,
    hasLiquidityLock: await checkLiquidityLock(tokenAddress),
    ownershipRenounced: await checkOwnershipRenounced(tokenAddress),
    buyTax,
    sellTax,
    maxWalletPercent: honeypotCheck.simulationResult?.maxTxOrFail ? 0 : 100,
  }
}

Gas Strategy for Sniping

To get in the first block, your transaction needs to be prioritized:

async function buildSnipeTransaction(
  tokenAddress: string,
  ethAmount: bigint,
  competitiveness: 'low' | 'medium' | 'high'
) {
  const gasMultipliers = { low: 1.5, medium: 3, high: 10 }
  const baseFee = (await provider.getFeeData()).gasPrice!
  
  const snipeTx = {
    to: UNISWAP_V2_ROUTER,
    value: ethAmount,
    data: buildSwapExactETHForTokens(tokenAddress, ethAmount),
    maxFeePerGas: baseFee * BigInt(gasMultipliers[competitiveness]),
    maxPriorityFeePerGas: ethers.parseUnits('5', 'gwei'),
    gasLimit: 300_000n,
  }
  
  return snipeTx
}

Solana Sniping with Raydium

On Solana, sniping is faster but requires different tooling:

import { Connection, PublicKey } from '@solana/web3.js'

const RAYDIUM_PROGRAM = new PublicKey('675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8')

// Use Helius enhanced WebSocket for ultra-low latency
const connection = new Connection('wss://mainnet.helius-rpc.com/?api-key=YOUR_KEY', {
  wsEndpoint: 'wss://mainnet.helius-rpc.com/?api-key=YOUR_KEY'
})

connection.onLogs(RAYDIUM_PROGRAM, async (logs) => {
  // Detect initialize2 = new pool created
  if (logs.logs.some(l => l.includes('ray_log') && l.includes('init'))) {
    await processNewPool(logs.signature)
  }
}, 'confirmed')

Risk Management for Snipers

Given the high failure rate of new token launches:

  1. Position size: Never snipe with more than 0.1 ETH per launch
  2. Auto-sell: Set automatic take-profit at 2-3x and stop-loss at -50%
  3. Daily limit: Cap daily snipe losses at 0.5 ETH total
  4. Filtering: Only snipe tokens with:
    • Contract verified on Etherscan
    • No mint function
    • No blacklist function
    • Liquidity locked (even if briefly)
// Auto take-profit / stop-loss monitoring
async function monitorPosition(tokenAddress: string, entryPrice: number, entryAmount: bigint) {
  const TAKE_PROFIT = 2.5  // 150% profit
  const STOP_LOSS = 0.5    // 50% loss
  
  const interval = setInterval(async () => {
    const currentPrice = await getTokenPrice(tokenAddress)
    const ratio = currentPrice / entryPrice
    
    if (ratio >= TAKE_PROFIT || ratio <= STOP_LOSS) {
      clearInterval(interval)
      await sellAllTokens(tokenAddress)
      console.log(`Position closed at ${((ratio - 1) * 100).toFixed(0)}% PnL`)
    }
  }, 5000) // Check every 5 seconds
}

The Reality of Sniping in 2026

Token sniping is extremely competitive. You're competing against:

  • Well-funded teams with co-located nodes
  • Bots with optimized Solidity execution
  • Validators/validators who can front-run you

For retail snipers, the key advantages are:

  • Better safety filters (the pros snipe everything; you snipe only quality)
  • Faster sell execution (take profits quickly)
  • Lower gas costs (use BSC or Solana instead of Ethereum mainnet)

Sniping should be a small percentage of your overall bot strategy โ€” not your primary income source.

Related Articles