Home Blog JS Drainer Architecture

JS Drainer Mechanics: Web3 Provider Hooking, RPC Batching & Anti-Analysis Obfuscation

1. Provider Hooking & EIP-6963 Multi-Wallet Discovery

Every crypto drainer begins execution in the browser DOM. The client-side JS engine hooks into injected Web3 providers (window.ethereum, window.solana, window.phantom, window.tronWeb). With modern wallets fighting over the global namespace, advanced scripts utilize EIP-6963 (Multi Injected Provider Discovery).

By listening for eip6963:announceProvider events, the frontend maps out all active wallet extensions simultaneously - MetaMask, Rabby, Coinbase Wallet, Solflare, Phantom - and prioritizes the provider holding the largest on-chain portfolio or highest-risk security profile.

2. High-Speed Balance Indexing & Multicall Batching

A drainer cannot afford slow latency while the user sits on the landing page. Within 200ms of wallet connection:

  • Atomic Multicall3 Scanning: The script dispatches a single batch eth_call querying hundreds of ERC-20 token balances, Uniswap v3 positions, Staked ETH balances, and Permit2 allowances simultaneously.
  • Solana Token Account Parsing: On Solana, the script invokes getTokenAccountsByOwner to index all Associated Token Accounts (ATAs) and Metaplex NFTs across standard SPL and Token-2022 programs.
  • Real-Time Price Valuation: Balances are immediately priced against live DEX feeds (DexScreener, Birdeye, Coingecko) via WebSocket, sorting the target assets by total dollar value.

3. Dynamic Signature Crafting & WebSocket Relayers

Once the asset order is calculated, the JS engine constructs the most optimal signature type based on the detected chain and token contract:

  1. EIP-712 Permit / Permit2: Crafts structured typed data vouchers that bypass on-chain gas costs for the victim.
  2. Versioned Tx (v0) with ALTs: Builds Solana transaction bundles interleaving transfer instructions with compute budget optimizations.
  3. WebSocket Relayer Handoff: As soon as the victim signs, the raw cryptographic signature is beamed over an encrypted WebSocket to the backend relayer node for instant mempool broadcast.

4. Anti-Debugging & Extension Sandbox Evasion

Modern security extensions (PocketUniverse, WalletGuard, Blockaid) intercept client-side RPC calls to simulate transaction outcomes. Drainer scripts deploy advanced browser evasion techniques:

  • Sandbox Fingerprinting: Inspecting headless Chrome properties, navigator user-agents, and automated extension proxies to detect automated crawlers.
  • Payload Decryption & Dynamic Imports: Core wallet communication logic remains AES-encrypted in bundled chunks, only decrypting in-memory once valid human mouse movement and authentic user interaction are verified.
  • Debugger Trapping: Infinite debugger; timing loops that freeze analysis when Chrome DevTools is opened.

5. Frequently Asked JS Drainer Queries

Can a JS drainer steal funds just by visiting a webpage?

No. Web3 browser extensions isolate private keys in secure extension sandboxes. A website's JS cannot extract private keys or initiate transfers without the user explicitly approving a wallet signature or transaction prompt.

How do security auditors detect malicious JS in dApps?

Auditors analyze obfuscated script bundles, monitor unauthorized eth_signTypedData_v4 requests, inspect external WebSocket relayer endpoints, and test contract permissions using RPC call interception.

Read our full breakdown on EVM wallet drainer internals or check our what is a crypto drainer overview.

If you’ve read this far, you understand how WebSocket relayers and EIP-6963 hooks bypass security tools