npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

mev-sandwich-detector

v1.0.2

Published

Detect MEV sandwich attacks on Ethereum transactions with Lightning micropayments

Readme

MEV Sandwich Detector

Detect MEV sandwich attacks on Ethereum transactions with automatic Lightning Network micropayments.

Features

  • 🔍 Real-time sandwich attack detection
  • ⚡ Automatic Lightning micropayments via L402
  • 🎯 Monitor specific addresses for MEV threats
  • 📊 MEV statistics and analytics
  • 🔐 Secure payment caching (5-minute TTL)

Installation

npm install mev-sandwich-detector

Quick Start

const MEVDetector = require('mev-sandwich-detector');

const detector = new MEVDetector({
  nwcUri: 'nostr+walletconnect://...' // From your Lightning wallet
});

// Check if a transaction is being sandwiched
const result = await detector.checkTransaction('0x1234...');
console.log(result);
// {
//   isSandwiched: true,
//   frontrunTx: '0xabc...',
//   backrunTx: '0xdef...',
//   estimatedLoss: '0.05 ETH',
//   confidence: 0.95
// }

API Reference

checkTransaction(txHash)

Check if a specific transaction is being sandwich attacked.

Parameters:

  • txHash (string): Ethereum transaction hash

Returns: Promise

  • isSandwiched (boolean): Whether sandwich attack detected
  • frontrunTx (string): Frontrunning transaction hash
  • backrunTx (string): Backrunning transaction hash
  • estimatedLoss (string): Estimated loss amount
  • confidence (number): Detection confidence (0-1)

Cost: 50 sats (~$0.05)

monitorAddress(options)

Monitor an address for real-time sandwich attacks.

Parameters:

  • options.address (string): Ethereum address to monitor
  • options.minValue (number): Minimum transaction value in ETH

Returns: Promise

  • subscriptionId (string): Monitoring subscription ID
  • websocketUrl (string): WebSocket connection URL

Cost: 100 sats (~$0.10) per alert

getStats(timeframe)

Get MEV sandwich attack statistics.

Parameters:

  • timeframe (string): '1h', '24h', or '7d'

Returns: Promise

  • totalAttacks (number): Total sandwich attacks detected
  • totalValue (string): Total value extracted by MEV bots
  • avgLoss (string): Average loss per victim
  • topVictims (Array): Most affected addresses

Cost: 20 sats (~$0.02)

analyzeRisk(tx)

Analyze pending transaction for sandwich risk before sending.

Parameters:

  • tx (Object): Transaction object with to, from, value, gasPrice

Returns: Promise

  • riskScore (number): Risk score (0-100)
  • recommendation (string): 'safe', 'caution', or 'danger'
  • suggestedGasPrice (string): Recommended gas price to avoid sandwich

Cost: 30 sats (~$0.03)

Pricing

| Method | Cost | Description | |--------|------|-------------| | checkTransaction() | 50 sats | Check single transaction | | monitorAddress() | 100 sats/alert | Real-time monitoring | | getStats() | 20 sats | MEV statistics | | analyzeRisk() | 30 sats | Pre-transaction risk analysis |

Configuration

Set your Lightning wallet connection:

# .env file
NWC_URI=nostr+walletconnect://your-wallet-uri-here

Get your NWC URI from:

  • Alby: Settings → Wallet Connect
  • Mutiny: Settings → Nostr Wallet Connect
  • Phoenix: Settings → Developer → NWC

How It Works

  1. Request Data → Package makes API call with your query
  2. Payment Required → Server responds with 402 + Lightning invoice
  3. Auto-Pay → Package pays automatically via your Lightning wallet
  4. Receive Data → MEV analysis returned instantly
  5. Cached → Payment cached for 5 minutes (no repayment needed)

Examples

Monitor Your Trading Bot

const detector = new MEVDetector({ nwcUri: process.env.NWC_URI });

// Monitor your bot's address
const subscription = await detector.monitorAddress({
  address: '0xYourBotAddress',
  minValue: 0.1 // Only alert for txs > 0.1 ETH
});

console.log('Monitoring started:', subscription.subscriptionId);

Check Before Swapping

const tx = {
  to: '0xUniswapRouter',
  from: '0xYourAddress',
  value: '1000000000000000000', // 1 ETH
  gasPrice: '50000000000' // 50 gwei
};

const risk = await detector.analyzeRisk(tx);

if (risk.recommendation === 'danger') {
  console.log('⚠️ High sandwich risk detected!');
  console.log('Suggested gas price:', risk.suggestedGasPrice);
}

License

MIT

Links

  • npm: https://www.npmjs.com/package/mev-sandwich-detector
  • GitHub: https://github.com/RodMillz/mev-sandwich-detector

Support

Questions? Open an issue on GitHub or reach out via Lightning: [email protected]