Skip to content

swiftnodes/sniper-bot-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sniper-Bot Template (Educational)

Real-time detection of new ERC-20 token launches on EVM chains. Listens to PairCreated events from major DEX factory contracts via WebSocket, fetches token metadata, and prints structured launch reports to stdout the moment a pair is created.

This is an educational template, not a trading bot. There is no buy logic, no wallet integration, no execution. Use it as a starting point to understand how on-chain real-time detection works.

git clone https://github.com/swiftnodes/sniper-bot-template
cd sniper-bot-template
cp .env.example .env             # add your SwiftNodes API key
npm install
CHAIN=base npm start

Output looks like:

[2026-05-13T14:23:11.501Z] BaseSwap
  New token: $PEPE (Pepe Coin)
  Address:   https://basescan.org/address/0x1234...
  Paired w:  WETH (0x4200...0006)
  Supply:    1,000,000,000,000 $PEPE
  Pair:      https://basescan.org/address/0xabcd...
  Tx:        https://basescan.org/tx/0xdead...

Supported chains

Five chains out of the box, each watching multiple DEX factories:

Chain DEX factories watched
Ethereum UniswapV2, SushiswapV2
Base UniswapV2, BaseSwap, Aerodrome
BNB Smart Chain PancakeV2, BiswapV2
Arbitrum One Camelot, SushiswapV2
Polygon QuickSwap, SushiswapV2

Add more chains or factories in src/chains.js — it's a single config object.

Architecture

src/
  chains.js     ← Per-chain config: WebSocket URL, factory contracts, quote tokens
  index.js      ← Subscribes to PairCreated logs, fetches token metadata, prints

Single-file design. Roughly 100 lines of actual logic. Read the source — there's nothing magic.

How it works

  1. Connect to a chain's WebSocket RPC endpoint (SwiftNodes' wss://rpc.swiftnodes.io/ws/{chain}).
  2. Subscribe to PairCreated(token0, token1, pair, uint256) event logs from each configured factory contract.
  3. When a log arrives, identify the "new" token — the one that isn't a known quote token (WETH, USDC, USDT, etc.).
  4. Fetch ERC-20 metadata (name, symbol, decimals, totalSupply) via parallel eth_call reads.
  5. Print a structured report with explorer links.

Total latency from on-chain pair creation to printed report: typically 200ms to 1.5s, depending on network and WebSocket subscription depth.

Setup

1. Get a SwiftNodes API key

Visit swiftnodes.io, connect a wallet (no email, no KYC), and grab your API key. Free tier covers most use cases.

2. Configure environment

cp .env.example .env

Edit .env:

SWIFTNODES_API_KEY=sn_aBcDeFgHiJkLmNoPqRsTuVwXyZ123456
CHAIN=base

3. Run

npm install
npm start            # uses CHAIN from .env
CHAIN=bsc npm start  # override per-run

Or use the convenience scripts:

npm run watch:base
npm run watch:bsc
npm run watch:eth

Extending this template

Add a new chain

Edit src/chains.js:

export const CHAINS = {
  // ... existing chains ...
  optimism: {
    name: "Optimism",
    wsUrl: ws("optimism"),
    nativeSymbol: "ETH",
    explorerTx: "https://optimistic.etherscan.io/tx/",
    explorerAddr: "https://optimistic.etherscan.io/address/",
    factories: [
      { name: "Velodrome", address: "0xF1046053aa5682b4F9a81b5481394DA16BE5FF5a" },
    ],
    quoteTokens: {
      WETH: "0x4200000000000000000000000000000000000006",
    },
  },
};

SwiftNodes supports 75+ chains — see the full list at swiftnodes.io/docs/supported-chains.

Add metadata filters

Many "launches" are honeypots or scams. Add filters before printing:

// In index.js, inside onLogs:
if (!meta.symbol || meta.symbol.length > 12) continue;       // skip nonsense
if (meta.totalSupply > 10n ** 30n) continue;                 // skip absurdly-supplied
if (!quoteToken) continue;                                   // skip non-USD-paired

Add a "potential rug" detector

Read additional contract state:

// Check if owner is renounced (set to 0x0)
const owner = await client.readContract({
  address: newToken,
  abi: [parseAbiItem("function owner() view returns (address)")],
  functionName: "owner",
}).catch(() => null);

// Check if there's a hidden transfer fee, max wallet, etc. — these are usually
// only visible by reading the contract source / bytecode, not state.

Add a Telegram/Discord notifier

Replace console.log(...) with HTTP POSTs to your bot's webhook URL.

Why SwiftNodes for this

WebSocket subscriptions are essential for real-time event detection. SwiftNodes:

  • WebSocket support on every plan including free tier
  • 75+ chains — multi-chain bots without juggling 5 different providers
  • No-KYC signup — sensible for hobbyist/educational projects
  • Health-checked failover — your subscription stays connected even when individual upstream nodes go down

For production sniping with actual capital at risk, you'd want a paid tier (or multiple providers in parallel) for redundancy and lower latency.

Disclaimer

Educational use only. Memecoin sniping carries serious risks:

  • Most new tokens are scams, honeypots, or rug pulls
  • Even legitimate launches can dump 90%+ within minutes
  • Front-running bots will routinely beat you to good entries
  • Profitable sniping requires actual edge — being fast alone is not enough
  • This template intentionally has no buying logic because writing one without proper risk management is a way to lose money quickly

If you do extend this into a real trading bot, study honeypot detection, slippage protection, gas optimization, and execution timing before risking funds.

License

MIT — fork, modify, ship.

Contributing

PRs welcome for:

  • Additional chains / factory addresses
  • Better metadata fetching (LP balance, top holders, etc.)
  • Honeypot detection heuristics
  • Notification integrations (Telegram, Discord, webhook)

About

Educational template for EVM new-pair detection. Listens to PairCreated events on Uniswap V2 forks via WebSocket and prints token launches in real time. 5 chains.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors