Get swap

Build a ready-to-sign swap transaction.

What /swap returns

GET /swap returns the best route and a ready-to-sign transaction object.

It includes the same routing fields as /quote plus tx.

Request parameters

  • tokenIn — input token address.

  • tokenOut — output token address.

  • amount — input amount in raw units.

  • recipient — address that receives the output tokens.

  • slippageBps — optional slippage in basis points. Default: 50.

  • excludeSources — optional comma-separated source IDs.

Example request

curl "https://api.dirol.io/api/v1/swap?tokenIn=0x3bd359C1119dA7Da1D913D1C4D2B7c461115433A&tokenOut=0x754704Bc059F8C67012fEd69BC8A327a5aafb603&amount=1000000000000000000&recipient=0x9603e52146d02Aa2eD5B6A71E43933ac07940B12"

Example response

{
  "tokenIn": "0x3bd359c1119da7da1d913d1c4d2b7c461115433a",
  "tokenOut": "0x754704bc059f8c67012fed69bc8a327a5aafb603",
  "amountIn": "1000000000000000000",
  "amountOut": "385274",
  "routes": [...],
  "priceImpactBps": 12,
  "amountInUsd": "0.39",
  "amountOutUsd": "0.39",
  "tx": {
    "to": "0x646462f4d0168A94fE1884c8ae82148a3618A18d",
    "data": "0xd53e7c84...",
    "value": "0",
    "estimatedGas": "350000"
  }
}

Approval flow

1

Get the swap transaction

Call /swap with your token pair, amount, and recipient.

Read the tx object from the response.

2

Approve ERC-20 input tokens

If the input token is an ERC-20, approve tx.to to spend amountIn.

Skip this step for native MON.

3

Send the transaction

Send the returned tx.data to tx.to.

Use tx.value for ERC-20 swaps. For native MON, send value = amountIn.

circle-info

For native MON swaps, use the WMON address as tokenIn when requesting /swap.

ethers.js example

viem example

Transaction fields

  • tx.to — Dirol aggregator contract.

  • tx.data — encoded calldata.

  • tx.value — native value to send.

  • tx.estimatedGas — estimated gas limit.

Notes

  • /swap is the endpoint to use for execution.

  • recipient must be a valid Monad address.

  • For ERC-20 inputs, approval must happen before the swap transaction.

  • For native MON, skip approval and send value = amountIn.

Last updated