Developing a sniper bot for token launch
In the first seconds after adding liquidity to a Uniswap v2/v3 or PancakeSwap pool, the difference between entering at block N and block N+3 can mean 5x vs 1.2x. Sniper bot is infrastructure for guaranteed early entry: mempool monitoring, listing event detection and sending transaction with correct gas price within milliseconds.
Where money is lost without proper bot
Naive approach — listen to PairCreated event from Uniswap factory and send swap. Problem: by the time the event hit the block and you read it, 2-5 seconds have passed. Competitors read mempool directly and see addLiquidity transaction before block inclusion.
Second common failure — tax tokens (tax tokens). Contract with _transfer override that withholds 10-30% on purchase, invisible through standard ABI. Bot buys but actually receives 25% less. Honeypot tokens block sale at all — sell always reverts.
How a proper sniper works
Mempool monitoring
Direct connection to node via WebSocket (eth_subscribe("newPendingTransactions")) gives pending transactions before block inclusion. For EVM networks, own node or private RPC (Chainstack, Alchemy with mempool access) is enough.
On Solana — subscribe to logsSubscribe with Raydium or Orca program ID filter. Latency critical: node must be geographically close to validators.
Simulation before purchase
Before sending real transaction — simulate via eth_call or tenderly_simulateTransaction. Check:
- Real token amount after transfer (detect tax)
- Sell possibility (does sell revert)
- Blacklist/whitelist functions in contract
async function simulateBuy(tokenAddress: string, amountIn: bigint): Promise<SimResult> {
const balanceBefore = await getTokenBalance(tokenAddress, botAddress);
// Simulate swap
await provider.send('eth_call', [{
from: botAddress,
to: ROUTER_ADDRESS,
data: encodeSwapExact(WETH, tokenAddress, amountIn)
}, 'pending']);
const balanceAfter = await getTokenBalance(tokenAddress, botAddress);
const received = balanceAfter - balanceBefore;
const taxRate = 1 - Number(received) / Number(expectedOutput);
return { received, taxRate, isSafe: taxRate < 0.05 };
}
Gas strategy
For EIP-1559 networks (Ethereum, Polygon): maxPriorityFeePerGas set to 2-3x current baseFee + aggressive tip. For BSC (legacy gas): monitor current gasPrice of competitors in mempool and set 10-20% above.
Anti-grief protection: gas limit — strict to operation, not unlimited. Honeypot contracts with infinite loop in _transfer burn all gas limit without anti-grief.
Stack and architecture
- TypeScript + viem — core bot logic
- ethers.js — fallback for some provider quirks
- WebSocket to private node — mempool subscription
- Redis — cache already-seen transactions, anti-double-buy
- PostgreSQL — log of all operations, P&L
Configuration via .env: RPC endpoint, private key in HSM or KMS (not plaintext), risk parameters (max buy amount, max tax tolerance, stop-loss).
Timeline estimates
Basic sniper for one DEX and one network — 3-5 days. Multi-chain version with honeypot detector and tax simulator — 1-2 weeks. Cost calculated individually.







