Skip to Content
New: a threat-model-first guide to choosing your network defence, plus the nym-smoldvpn dVPN package and nym-swizzle sender hygiene.
DevelopersDemosRouting the Railgun SDK

Routing the Railgun SDK through the mixnet

Nym hides the network layer: every Ethereum RPC call goes through the mixnet via mixFetch, so the RPC node and your ISP cannot link you to the query, and Railgun hides the application layer, as shielded notes break the on-chain link between sender, receiver, and amount. The Railgun demo puts the RPC traffic of the whole Railgun SDK behind the mixnet. Railgun keeps its own demo of a Railgun wallet over Nym: nym-demo on GitLab.

How the Railgun SDK routes through the mixnet

The ENS demo swapped one provider’s transport, but Railgun constructs its own providers internally, so routing only your provider would leak the engine’s RPC to clearnet. Instead, install a global ethers transport: FetchRequest.registerGetUrl routes every ethers HTTP call in the page through mixFetch, including the ones the Railgun engine makes. The same pattern works in any ethers-based app.

import { FetchRequest } from 'ethers'; import { mixFetch } from '@nymproject/mix-fetch'; // Every ethers HTTP request in the process now goes through the mixnet. FetchRequest.registerGetUrl(async (req) => { const res = await mixFetch(req.url, { method: req.method, headers: req.headers, // ethers' FetchRequest.body is Uint8Array | null; cast for RequestInit. body: (req.body ?? undefined) as BodyInit | undefined, }); return { statusCode: res.status, statusMessage: res.statusText, headers: Object.fromEntries(res.headers), body: new Uint8Array(await res.arrayBuffer()), }; });

registerGetUrl is global static state on the FetchRequest class, so this only works if ethers is a single instance across your bundle. If your app and Railgun resolve to different ethers copies, the handler installs on one and the engine uses the other. Pin the exact version Railgun peer-depends on.

The block above is the shape of the shim. One caveat the real version adds: browser fetch decompresses gzip transparently and mixFetch does not, so the handler must run a DecompressionStream over each response before handing it back to ethers. The ENS demo has a handler with decompression (decompressBody) in components/demos/ens/lib.ts.

On npm: @nymproject/mix-fetch, @railgun-community/wallet, and ethers.

Shielding is a four-step flow, all over the mixnet: sign a shield key, estimate gas, populate the transaction, then sign and broadcast. The broadcast that lands on Sepolia is observable on Etherscan, but the IP that submitted it stays hidden.

Glossary

  • Mixnet. An overlay network that routes your traffic through several relays, mixed in with everyone else's, so no single point can link sender to receiver. See mixnet mode.
  • Entry gateway. Your first hop into the mixnet. The browser holds one WebSocket to it, and all tunnelled traffic travels over that single connection as opaque frames. See Nym nodes.
  • IPR (IP Packet Router), the exit. Where traffic leaves the mixnet for the public internet. The destination sees the IPR's IP, not yours. See exit services.
  • SURB (single-use reply block). A prepaid, single-use return envelope. The exit replies through it without ever learning your address. See anonymous replies.
  • Cover traffic / Poisson timing. Decoy packets sent on randomised timing, so your real traffic blends into a steady stream. See cover traffic.
  • mixFetch. A fetch()-shaped function from @nymproject/mix-fetch. It runs the mixnet client (smolmix) in a Web Worker, so each request goes through the mixnet rather than the browser's network stack.
Last updated on