A free, public DEX aggregator. The routing core is fully on-chain — call zQuoter from any Ethereum, Base or Robinhood RPC and get ready-to-send calldata, no keys and no intermediary. The hosted REST API wraps that in one HTTP call and additionally shops the trade against the off-chain aggregators that serve the chain you asked for, returning whichever wins.
One HTTP call returns the best quote + ready-to-send transaction. No SDK, no ABI encoding, no Multicall3 batching. The service runs all zQuoter route strategies on-chain (single-hop, 2-hop hub, split, hybrid split, 3-hop) and in parallel requests quotes from Bebop, Enso, 0x, 1inch, OKX, KyberSwap, Paraswap and OpenOcean, then returns the single best output.
Base URL https://api.zfi.wei.is. It is a hosted Node service (aggregator API keys are held server-side so you don't need any) — unlike direct zQuoter calls, it is a trusted third party in the quoting path. Always check the returned tx.to and decode the calldata before signing.
Returns the optimal swap route and transaction calldata.
Parameters
tokenIn — ERC20 address or 0x0000...0000 for ETH (required)tokenOut — ERC20 address or 0x0000...0000 for ETH (required)amount — raw integer in tokenIn's smallest unit (or tokenOut's if exactOut=true) (required)to — recipient / taker address. Pass it for executable calldata; without it the quote is still priced correctly but the on-chain route targets address(0) and aggregator routes are quoted for a placeholder taker, so the returned tx is not safe to send (optional)slippage — basis points, 1–5000, default 50 (0.5%). Split / multi-hop legs automatically use 3× this, clamped to 150–500 bps, since per-leg slippage compounds (optional)exactOut — true for exact output mode. Off-chain aggregators are skipped in this mode, so the quote is zQuoter-only (optional)chainId — 1 (Ethereum, default), 8453 (Base) or 4663 (Robinhood). An unsupported id is a 400 rather than a silent fallback to Ethereum. The response echoes the chainId it priced (optional)Chains
zQuoter, zRouter and Multicall3 sit at the same addresses on all three chains, so the on-chain half of the API is identical everywhere and an on-chain win returns the same zRouter as tx.to. Two things differ:
GET /health lists the lanes each chain actually runssource field is an enum position, and the enums differ — index 1 is SushiSwap on Ethereum but Aerodrome on Base, index 5 Curve on Ethereum but Aerodrome CL on Base. Base's enum ends at index 6 (WETH Wrap). Robinhood keeps Ethereum's enum shape, though only Uniswap V2/V3/V4 have deployments there, so the other slots never win| Chain | chainId | Off-chain lanes |
|---|---|---|
| Ethereum | 1 | Bebop, Enso, 0x, 1inch, OKX, KyberSwap, Odos, Paraswap, OpenOcean |
| Base | 8453 | Bebop, Enso, 0x, 1inch, KyberSwap, Odos, Paraswap, OpenOcean |
| Robinhood | 4663 | KyberSwap, Paraswap |
Odos is switched off for now, and OpenOcean answers only with a key this deployment does not hold, so neither returns a route today. OKX is absent off Ethereum because its TokenApprove spender is a different contract per chain and the mainnet one has no code on either L2 — approving it would be a no-op. A lane only appears for a chain where its approval target actually exists.
Example — the same swap on Base:
curl "https://api.zfi.wei.is/quote?chainId=8453&tokenIn=0x0000000000000000000000000000000000000000&tokenOut=0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913&amount=1000000000000000000"
Example — swap 1 ETH for USDC:
curl "https://api.zfi.wei.is/quote?tokenIn=0x0000000000000000000000000000000000000000&tokenOut=0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48&amount=1000000000000000000"
Response:
{
"bestRoute": {
"expectedOutput": "1897615271",
"source": "KyberSwap",
"isTwoHop": false,
"isSplit": false
},
"tx": {
"to": "0x6131B5fae19EA4f9D964eAc0408E4408b66337b5",
"data": "0x...",
"value": "1000000000000000000"
},
"allQuotes": [
{ "source": "KyberSwap", "amountOut": "1897615271" },
{ "source": "Uniswap V3", "amountOut": "1895102204" },
{ "source": "Uniswap V2", "amountOut": "1845000000" }
],
"approvalTarget": "0x6131B5fae19EA4f9D964eAc0408E4408b66337b5"
}
bestRoute.source — winning venue. An AMM name (e.g. Uniswap V3), a composite like Uniswap V3 + zAMM (hybrid) or A → B → C for multi-hop, or an aggregator nametx.to — not always zRouter. It is zRouter when an on-chain zQuoter route wins, and the aggregator's own settlement contract when one of them wins. Always send to the returned addresstx.value — wei to attach; "0" for ERC20 inputallQuotes — every venue that returned a price, sorted best-firstapprovalTarget — the contract to approve for ERC20 input. zRouter for on-chain routes, the aggregator's spender otherwise. It is often not the same as tx.to: several aggregators pull tokens through a spender contract but settle at a different address (Paraswap, for one). Approve approvalTarget, send to tx.toExecute the swap:
const quote = await fetch("https://api.zfi.wei.is/quote?...").then(r => r.json());
// ERC20 input: approve the route's spender first (skip for native ETH)
await token.approve(quote.approvalTarget, amountIn);
await signer.sendTransaction({
to: quote.tx.to,
data: quote.tx.data,
value: quote.tx.value
});
Errors — JSON {"error": "..."} with 400 (bad or missing params), 405 (wrong method), 502 (no viable route / upstream failure).
Other endpoints:
GET /health — returns {status, chains}, where chains lists each supported chainId, its name, and lanes, the off-chain aggregators asked for itGET / — 302 redirect to this pagePOST /simulate — body {from, to, data, value, chainId}; runs a Tenderly simulation and returns {id, url, status} with a shareable link. chainId defaults to 1 and accepts 8453; Robinhood is refused with a 400 because Tenderly has no such network. Returns 503 if the deployment has no Tenderly credentials configuredOpen to all origins (CORS *), no API keys or signup required. Please be reasonable with request volume — each /quote fans out to a dozen upstreams.
zQuoter — read-only route discovery and calldata builder.
0x000000bd2db80567c23e353ca95a251c573cbf9b
zRouter — swap executor. Send the calldata built by zQuoter here.
0x000000000000FB114709235f1ccBFfb925F600e4
Aggregates Uniswap V2/V3/V4, SushiSwap, Curve, zAMM, and Lido. Zero protocol fees.
All routing is deterministic and happens on-chain via view functions. The REST API above handles this for you, but you can also call the contracts directly. The pattern is two steps:
No solvers, no relay infrastructure. Just an RPC call to get calldata, then a transaction to execute it.
Swap 1 ETH for USDC using ethers.js and buildBestSwapViaETHMulticall — the primary entry point, returning the best of single-hop and 2-hop hub routing:
import { ethers } from "ethers";
const ZQUOTER = "0x000000bd2db80567c23e353ca95a251c573cbf9b";
const ZROUTER = "0x000000000000FB114709235f1ccBFfb925F600e4";
const quoterAbi = [
"function buildBestSwapViaETHMulticall(address to, address refundTo, bool exactOut, address tokenIn, address tokenOut, uint256 swapAmount, uint256 slippageBps, uint256 deadline) view returns (tuple(uint8 source, uint256 feeBps, uint256 amountIn, uint256 amountOut) a, tuple(uint8 source, uint256 feeBps, uint256 amountIn, uint256 amountOut) b, bytes[] calls, bytes multicall, uint256 msgValue)"
];
const provider = new ethers.JsonRpcProvider("https://ethereum.publicnode.com");
const signer = /* your wallet signer */;
const me = await signer.getAddress();
const quoter = new ethers.Contract(ZQUOTER, quoterAbi, provider);
const USDC = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";
const ETH = "0x0000000000000000000000000000000000000000";
const oneETH = ethers.parseEther("1");
const deadline = BigInt(Math.floor(Date.now() / 1000) + 300);
// 1. Quote (view call — free, no gas)
const r = await quoter.buildBestSwapViaETHMulticall(
me, // to: recipient
me, // refundTo: excess ETH / leftover MID refunds
false, // exactOut: false = exact input
ETH, // tokenIn
USDC, // tokenOut
oneETH, // swapAmount: 1 ETH
50n, // slippageBps: 0.5%
deadline
);
// b is the second leg; b.amountOut == 0 means the route is single-hop.
const out = r.b.amountOut > 0n ? r.b.amountOut : r.a.amountOut;
console.log("Expected USDC out:", ethers.formatUnits(out, 6));
// 2. Execute (send transaction)
const tx = await signer.sendTransaction({
to: ZROUTER,
data: r.multicall,
value: r.msgValue
});
console.log("Tx:", tx.hash);
For exotic pairs with no direct or hub route, fall back to build3HopMulticall. For the best possible output, also compare buildSplitSwap and buildHybridSplit — see Best Quote Selection.
For ERC20 → ERC20 or ERC20 → ETH swaps, the user must first approve zRouter to spend their tokens.
// Approve zRouter to spend your USDC
const token = new ethers.Contract(USDC, [
"function approve(address,uint256) returns (bool)"
], signer);
await token.approve(ZROUTER, ethers.MaxUint256);
// Then quote and execute as before, with tokenIn = USDC
const r = await quoter.buildBestSwapViaETHMulticall(
me, me, false,
USDC, // tokenIn: USDC
ETH, // tokenOut: ETH
ethers.parseUnits("1000", 6), // 1000 USDC
50n, deadline
);
const tx = await signer.sendTransaction({
to: ZROUTER,
data: r.multicall,
value: r.msgValue // 0 for ERC20 input
});
zRouter also supports permit and permit2TransferFrom for gasless approvals. These can be batched into a multicall alongside the swap calls.
There is no single-call auto-router. Earlier versions shipped one (buildSwapAuto); it was removed because it was a cascade, not a comparison — it took the first depth that built rather than the best across strategies, so it could return worse output than comparing the builders yourself. Compose it caller-side in a few lines:
// 1. Best of {single-hop, 2-hop hub}
try {
const r = await quoter.buildBestSwapViaETHMulticall(
me, me, exactOut, tokenIn, tokenOut, amount, 50n, deadline);
if (r.multicall.length > 2) return r; // routed
} catch {}
// 2. 3-hop last resort for exotic pairs
return await quoter.build3HopMulticall(
me, exactOut, tokenIn, tokenOut, amount, 50n, deadline);
Prefer the full comparison in Best Quote Selection when you want maximum output — it additionally weighs buildSplitSwap and buildHybridSplit, which the old one-call path never considered.
Direct single-hop best-of quote and calldata. Returns a flat (Quote, calldata, amountLimit, msgValue) rather than the two-leg shape, with no multicall envelope when the result is a raw single-hop swap routed directly to to. Use when you know a single-hop route exists and want minimum overhead.
Lower-level builder that explicitly returns both legs of a potential 2-hop hub route plus the individual call bytes. Use when you need to inspect or modify the multicall (e.g. prepending permit calls, custom sweeps).
refundTo — address for excess ETH / leftover MID refunds (usually msg.sender)a, b — Quote structs for leg A and leg B (b.amountOut == 0 for single-hop)calls — individual call bytes for each leg (for prepending permit / custom actions)multicall — encoded multicall(bytes[]) calldataSplits liquidity across two AMMs in parallel for better execution on large trades.
Combines a single-hop and a 2-hop route in parallel. Captures cases where splitting across route depths beats any single strategy.
Three-hop routing through two hub tokens for exotic pairs.
Returns the best single-hop quote and all individual AMM quotes across the fee-tier grid (V2, Sushi, zAMM, V3, V4). Useful for displaying price comparison across venues. Curve and Lido are not in this grid — quote those with quoteCurve / quoteLido, or use buildBestSwap, which weighs all seven sources.
Auto-discovers Curve pools via MetaRegistry and returns the best Curve-only quote.
Direct Lido staking quote for ETH → stETH or wstETH.
Low-level quoting for specific venues. Available on the base quoter at 0x658bF1A6608210FDE7310760f391AD4eC8006A5F.
Do not call quoteV4 on the base quoter. Its swap-fee expression breaks once a V4 pool has a protocol fee set (live since Uniswap enabled them at block 25623201), producing a bogus fee and either a revert or a garbage price. Call it on the corrected V4 quoter at 0x56033EBF90EbdEf9D74b38e5F7201c0624EFef01 instead — same signature. (It supersedes 0x00005d8a3675b7b00BA172Aa85485Fc5D23121B6, which this page named until the zQuoter above was repointed; the live zQuoter's bytecode references the new one.) The main zQuoter above already routes V4 through it, so getQuotes and every build* function are unaffected.
struct Quote {
AMM source; // 0=UNI_V2, 1=SUSHI, 2=ZAMM, 3=UNI_V3,
// 4=UNI_V4, 5=CURVE, 6=LIDO, 7=WETH_WRAP
uint256 feeBps; // pool fee in basis points
uint256 amountIn;
uint256 amountOut;
}
For maximum output, compare multiple route strategies and take the best. This is what the swap page does. (If you don't need the cross-depth comparison, buildBestSwapViaETHMulticall alone is enough.)
const [best, split, hybrid] = await Promise.allSettled([
quoter.buildBestSwapViaETHMulticall(
me, me, false, tokenIn, tokenOut,
amountIn, 50n, deadline),
quoter.buildSplitSwap(
me, tokenIn, tokenOut,
amountIn, 50n, deadline),
quoter.buildHybridSplit(
me, tokenIn, tokenOut,
amountIn, 50n, deadline)
]);
// Pick the best output across all strategies
function outputOf(r) {
// buildBest/3hop: b is final leg (0 for single-hop)
if (r.a) return r.b?.amountOut > 0n ? r.b.amountOut : r.a.amountOut;
// split/hybrid: sum both legs (same output token)
return r.legs[0].amountOut + r.legs[1].amountOut;
}
let winner = best.value;
let winnerOut = outputOf(winner);
for (const r of [split, hybrid]) {
if (r.status === "fulfilled" && outputOf(r.value) > winnerOut) {
winner = r.value;
winnerOut = outputOf(winner);
}
}
// Send the winning route
await signer.sendTransaction({
to: ZROUTER,
data: winner.multicall,
value: winner.msgValue
});
For gasless approvals, build a multicall that includes a permit call before the swap legs:
const routerAbi = [
"function multicall(bytes[]) payable returns (bytes[])",
"function permit(address token, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s)",
"function permit2TransferFrom(address token, uint256 amount, uint256 nonce, uint256 deadline, bytes signature)"
];
const routerIface = new ethers.Interface(routerAbi);
// Sign EIP-2612 permit off-chain, then:
const permitCall = routerIface.encodeFunctionData("permit", [
tokenAddress, ethers.MaxUint256, permitDeadline, v, r, s
]);
const tx = await signer.sendTransaction({
to: ZROUTER,
data: routerIface.encodeFunctionData("multicall", [
[permitCall, ...result.calls]
]),
value: result.msgValue
});
You generally don't call these directly — zQuoter builds the calldata for you. Listed here for reference.
Batches multiple calls atomically. Each call is delegatecall'd in sequence. If any sub-call reverts, the entire batch reverts.
Transfers tokens into the router and marks them in transient storage for multi-leg chaining.
Sends tokens from the router to a recipient. Pass amount=0 to sweep full balance.
ETH → WETH. Pass amount=0 to wrap full ETH balance.
WETH → ETH.
Direct Lido staking via msg.value.
For 2-hop and 3-hop routes, zQuoter automatically routes through the most liquid hub:
WETH 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 USDC 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 USDT 0xdAC17F958D2ee523a2206206994597C13D831ec7 DAI 0x6B175474E89094C44Da98b954EedeAC495271d0F WBTC 0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599 wstETH 0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0
ETH (native) address(0) WETH 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 USDC 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 USDT 0xdAC17F958D2ee523a2206206994597C13D831ec7 DAI 0x6B175474E89094C44Da98b954EedeAC495271d0F WBTC 0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599 stETH 0xae7ab96520DE3A18E5e111B5eaAb095312D7fE84 wstETH 0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0
view — they cost no gas and can be called from any RPCaddress(0) for native ETH in both tokenIn and tokenOut50 bps, each leg tolerates 0.5% independentlydeadline parameter is a unix timestamp. Set it to now + 300 (5 minutes) for typical swapsdeadline = type(uint256).max to swapV2swapCurve calldata may not target optimally. For these, you can get a better rate by using quoteCurve for the quote, then building your own calldata via zRouter's execute or snwap functions to call the pool directly. This pattern works as a general escape hatch for any external protocol or pool with a custom interfacezRouter's snwap and execute functions let you route through any external contract — useful for legacy pools, staking protocols, or any on-chain action that isn't natively supported by the swap functions.
// Example: direct ETH→stETH via legacy Curve pool
const CURVE_POOL = "0xDC24316b9AE028F1497c275EB9192a3Ea0f67022";
const exchangeData = curveIface.encodeFunctionData(
"exchange", [0, 1, amountIn, minOut] // int128 indices
);
const routerIface = new ethers.Interface([
"function multicall(bytes[]) payable returns (bytes[])",
"function snwap(address tokenIn, uint256 amountIn, address recipient, address tokenOut, uint256 amountOutMin, address executor, bytes executorData) payable returns (uint256 amountOut)"
]);
// snwap: executes arbitrary calldata with slippage protection
const tx = await signer.sendTransaction({
to: ZROUTER,
data: routerIface.encodeFunctionData("snwap", [
ETH, // tokenIn
amountIn, // amountIn
me, // recipient
STETH, // tokenOut
minOut, // amountOutMin (enforced by router)
CURVE_POOL, // executor (target contract)
exchangeData // calldata forwarded to executor
]),
value: amountIn
});
snwap measures the recipient's balance change and reverts if amountOutMin isn't met — so you get slippage protection regardless of the external contract's interface.