On-Chain API

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.

REST API

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.

GET /quote

Returns the optimal swap route and transaction calldata.

Parameters

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:

ChainchainIdOff-chain lanes
Ethereum1Bebop, Enso, 0x, 1inch, OKX, KyberSwap, Odos, Paraswap, OpenOcean
Base8453Bebop, Enso, 0x, 1inch, KyberSwap, Odos, Paraswap, OpenOcean
Robinhood4663KyberSwap, 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"
}

Execute 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:

Open to all origins (CORS *), no API keys or signup required. Please be reasonable with request volume — each /quote fans out to a dozen upstreams.


Contracts

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.


How It Works

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.


Quick Start

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.


ERC20 Swaps

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.


zQuoter Functions

Auto-routing cascadepattern

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.

buildBestSwap

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.

buildBestSwap(address to, bool exactOut, address tokenIn, address tokenOut, uint256 swapAmount, uint256 slippageBps, uint256 deadline) → (Quote best, bytes callData, uint256 amountLimit, uint256 msgValue)

buildBestSwapViaETHMulticall

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).

buildBestSwapViaETHMulticall(address to, address refundTo, bool exactOut, address tokenIn, address tokenOut, uint256 swapAmount, uint256 slippageBps, uint256 deadline) → (Quote a, Quote b, bytes[] calls, bytes multicall, uint256 msgValue)

buildSplitSwap

Splits liquidity across two AMMs in parallel for better execution on large trades.

buildSplitSwap(address to, address tokenIn, address tokenOut, uint256 swapAmount, uint256 slippageBps, uint256 deadline) → (Quote[2] legs, bytes multicall, uint256 msgValue)

buildHybridSplit

Combines a single-hop and a 2-hop route in parallel. Captures cases where splitting across route depths beats any single strategy.

buildHybridSplit(address to, address tokenIn, address tokenOut, uint256 swapAmount, uint256 slippageBps, uint256 deadline) → (Quote[2] legs, bytes multicall, uint256 msgValue)

build3HopMulticall

Three-hop routing through two hub tokens for exotic pairs.

build3HopMulticall(address to, bool exactOut, address tokenIn, address tokenOut, uint256 swapAmount, uint256 slippageBps, uint256 deadline) → (Quote a, Quote b, Quote c, bytes[] calls, bytes multicall, uint256 msgValue)

getQuotesview

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.

getQuotes(bool exactOut, address tokenIn, address tokenOut, uint256 swapAmount) → (Quote best, Quote[] quotes)

quoteCurveview

Auto-discovers Curve pools via MetaRegistry and returns the best Curve-only quote.

quoteCurve(bool exactOut, address tokenIn, address tokenOut, uint256 swapAmount, uint256 maxCandidates) → (uint256 amountIn, uint256 amountOut, address bestPool, bool usedUnderlying, bool usedStable, uint8 iIndex, uint8 jIndex)

quoteLidoview

Direct Lido staking quote for ETH → stETH or wstETH.

quoteLido(bool exactOut, address tokenOut, uint256 swapAmount) → (uint256 amountIn, uint256 amountOut)

Individual AMM Quotesview

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.

quoteV2(bool exactOut, address tokenIn, address tokenOut, uint256 swapAmount, bool sushi) → (uint256 amountIn, uint256 amountOut)
quoteV3(bool exactOut, address tokenIn, address tokenOut, uint24 fee, uint256 swapAmount) → (uint256 amountIn, uint256 amountOut)
quoteV4(bool exactOut, address tokenIn, address tokenOut, uint24 fee, int24 tickSpacing, address hooks, uint256 swapAmount) → (uint256 amountIn, uint256 amountOut)
quoteZAMM(bool exactOut, uint256 feeOrHook, address tokenIn, address tokenOut, uint256 idIn, uint256 idOut, uint256 swapAmount) → (uint256 amountIn, uint256 amountOut)

Quote Struct

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;
}

Best Quote Selection

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
});

Prepending Permit Calls

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
});

zRouter Functions

You generally don't call these directly — zQuoter builds the calldata for you. Listed here for reference.

multicall

Batches multiple calls atomically. Each call is delegatecall'd in sequence. If any sub-call reverts, the entire batch reverts.

multicall(bytes[] data) payable → bytes[] results

Swap Functions

swapV2(address to, bool exactOut, address tokenIn, address tokenOut, uint256 swapAmount, uint256 amountLimit, uint256 deadline) payable
swapV3(address to, bool exactOut, uint24 swapFee, address tokenIn, address tokenOut, uint256 swapAmount, uint256 amountLimit, uint256 deadline) payable
swapV4(address to, bool exactOut, uint24 swapFee, int24 tickSpace, address tokenIn, address tokenOut, uint256 swapAmount, uint256 amountLimit, uint256 deadline) payable
swapVZ(address to, bool exactOut, uint256 feeOrHook, address tokenIn, address tokenOut, uint256 idIn, uint256 idOut, uint256 swapAmount, uint256 amountLimit, uint256 deadline) payable
swapCurve(address to, bool exactOut, address[11] route, uint256[4][5] swapParams, address tokenIn, address tokenOut, uint256 swapAmount, uint256 amountLimit, uint256 deadline) payable

Helpers

deposit(address token, uint256 id, uint256 amount) payable

Transfers tokens into the router and marks them in transient storage for multi-leg chaining.

sweep(address token, uint256 id, uint256 amount, address to) payable

Sends tokens from the router to a recipient. Pass amount=0 to sweep full balance.

wrap(uint256 amount) payable

ETH → WETH. Pass amount=0 to wrap full ETH balance.

unwrap(uint256 amount) payable

WETH → ETH.

exactETHToSTETH(address to) payable → uint256 shares
exactETHToWSTETH(address to) payable → uint256 wstOut

Direct Lido staking via msg.value.


Hub Tokens

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

Common Addresses

ETH (native)   address(0)
WETH           0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
USDC           0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48
USDT           0xdAC17F958D2ee523a2206206994597C13D831ec7
DAI            0x6B175474E89094C44Da98b954EedeAC495271d0F
WBTC           0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599
stETH          0xae7ab96520DE3A18E5e111B5eaAb095312D7fE84
wstETH         0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0

Notes


Advanced: Custom Zaps via execute / snwap

zRouter'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.


Source