ENS over the mixnet
This demo does an ENS lookup (name to address to IPFS website) with ethers.js . Every JSON-RPC and IPFS request of the lookup goes through the Nym mixnet. The demo turns off CCIP-Read, because an offchain resolver would make a direct request. The optional Verify IP routing check also makes one direct request to ipinfo.io, for comparison. The Ethereum RPC node and the IPFS gateway see the IPR exit’s IP address, not yours, and your ISP cannot see which names or sites you reach. The trade-off is latency: every packet takes a multi-relay path, so requests are slower than a direct route.
Using this in your own app
The ENS demo shows the integration pattern for an Ethereum dApp, a web3 app, or a browser extension wallet. Two questions on the developers overview decide the package. Answer them before you write code.
A browser runs a WASM client, and an Ethereum RPC provider is a destination that
does not run Nym. Those two answers put you in the Browser / WebView row in proxy
mode, which selects mix-fetch. The
developers overview explains both axes, and
Choose a Defence starts from the adversary
rather than from the tool.
Proxy mode is the weaker of the two positions, so choose it deliberately. Exit Gateway Services sets out what the exit gateway observes. Baseline hygiene covers the request-shape discipline that the transport layer does not provide.
The adapter below connects mix-fetch to ethers. ENS resolution is only the
example. The mechanism applies to every request ethers makes: a balance read, a
name resolution, or a signed transaction. It does not change signing or key
handling, so a wallet keeps its existing mechanism.
For a wallet connecting to the Nyx chain rather than to Ethereum, that is a different job: see Cosmos Kit.
How ENS resolution over the mixnet works
The whole integration is one adapter. ethers v6 exposes
FetchRequest.getUrlFunc as a settable property, so you replace its HTTP
transport with a function that calls mixFetch. To
ethers it looks like an ordinary fetch; to the mixnet, ethers looks like any
other caller.
import { JsonRpcProvider, FetchRequest } from 'ethers';
import { mixFetch } from '@nymproject/mix-fetch';
function buildProvider(rpcUrl: string): JsonRpcProvider {
const base = new FetchRequest(rpcUrl);
// Route every JSON-RPC call through mixFetch, renaming the response
// fields ethers expects (status -> statusCode, statusText -> statusMessage).
base.getUrlFunc = 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()),
};
};
// staticNetwork skips the eth_chainId probe: one mixnet round trip saved.
return new JsonRpcProvider(base, 'mainnet', { staticNetwork: true });
}Browser fetch decompresses compressed responses and mixFetch does not, so the demo adds a DecompressionStream step to each response that has a gzip or deflate Content-Encoding (Cloudflare gzips RPC replies). The full version with decompression and per-call logging is in components/demos/ens/lib.ts.
On npm: @nymproject/mix-fetch and ethers.
The lookup itself is three steps, each an Ethereum call or HTTPS GET over the same tunnel:
- Resolve address.
provider.resolveName(name)under the hood reads the ENS Registry’sresolver(node)to find the resolver contract, then callsresolver.addr(node)for the Ethereum address (ethers may add an EIP-165supportsInterfaceprobe in between).nodeis the namehash (recursive keccak256 over the labels). - Get contenthash. One more
eth_call:resolver.contenthash(node). ethers decodes the EIP-1577 multicodec bytes to a URI; this demo handlesipfs://. - Fetch from IPFS. A plain HTTPS GET to a gateway with the CID as a subdomain
or path label. CIDv0 (
Qm...) is re-encoded as CIDv1 (bafy...) for subdomain gateways, since DNS is case-insensitive.
Try it
Connect to bring the tunnel up (a default IPR exit is pinned; tick Use random IPR for auto-discovery), click Verify IP routing to confirm traffic exits through Nym, then run the three steps.
What to expect
- The first request is the slow one. Connecting builds the mixnet client and handshakes with the IPR; no TCP or TLS yet. The first request to a host then runs a TCP and TLS handshake carried as IP packets over the mixnet (several sequential round trips). smolmix keeps that connection warm and reuses it, so later requests to the same host are faster. A long pause at this step is normal.
- You will not see the tunnelled requests in DevTools. The RPC and IPFS requests never touch the browser’s
fetch. They leave the worker as encrypted packets over a single WebSocket to the entry gateway, which is the one connection the Network tab shows. The exception is Verify IP routing, which makes one direct clearnet call to ipinfo.io for comparison. - Rate limiting. Public IPFS gateways and Ethereum RPCs rate-limit shared IP addresses. If requests fail with 403, 429, or connection errors, the provider has probably flagged the exit gateway’s IP address. Reload the page, then tick Use random IPR before you connect. A reload clears the tick. The client then picks an IPR exit at random, weighted by performance score, and it can pick the same one again, so retry if requests still fail.
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.