Swap API

One endpoint quotes and encodes everything: split simulation across live fee tiers, a global minimum-output floor, and a single SwapRouter02 multicall. Every pattern below is the exact flow the Splitshot app uses, proven end to end on mainnet.

Parameters

text
GET https://splitshot-dex-be.onrender.com/v1/quote
  tokenIn      0x-address (use WETH 0x0Bd7D308f8E1639FAb988df18A8011f41EAcAD73 for native ETH)
  tokenOut     0x-address
  amountIn     positive uint string (wei); with exactOut=1 this is the desired OUTPUT
  recipient    optional 0x-address (required to get tx calldata)
  slippageBps  0..500, or "auto" (tolerance derived from the trade's own price impact)
  exactOut     1 -> quote by desired output; response adds amountInMaximum
  nativeOut    1 -> append unwrapWETH9 so the recipient gets native ETH
  nativeIn     1 -> informational; send amountIn as msg.value (router wraps it)

Native ETH in

typescript
// Native ETH in: no approval, no wrap step. Send value with the tx.
const q = await (await fetch(`${base}/v1/quote?tokenIn=${WETH}&tokenOut=${USDG}&amountIn=${wei}&recipient=${me}&slippageBps=auto&nativeIn=1`)).json()
await wallet.sendTransaction({ to: q.tx.to, data: q.tx.data, value: BigInt(q.amountIn) })

Native ETH out

typescript
// Native ETH out: legs pay the router, unwrapWETH9 forwards ETH to you
const q = await (await fetch(`${base}/v1/quote?tokenIn=${USDG}&tokenOut=${WETH}&amountIn=${wei}&recipient=${me}&nativeOut=1`)).json()
// one-time: approve SwapRouter02 for tokenIn, then:
await wallet.sendTransaction({ to: q.tx.to, data: q.tx.data })

Exact output

typescript
// Exact output: "I want exactly 100 USDG". Pay up to amountInMaximum, rest refunds.
const q = await (await fetch(`${base}/v1/quote?tokenIn=${WETH}&tokenOut=${USDG}&amountIn=${wantOutWei}&recipient=${me}&exactOut=1&nativeIn=1`)).json()
await wallet.sendTransaction({ to: q.tx.to, data: q.tx.data, value: BigInt(q.amountInMaximum) })

Auto slippage

slippageBps=auto probes 1% of the trade to estimate the mid rate, sets tolerance to half the measured impact plus 10 bps, clamped to [10, 500], and echoes autoSlippageBps and priceImpactBps in the response. Small liquid trades land near 10-25 bps instead of a flat 50.