Swap

Generate transaction calldata to perform a token swap on Nabla.

Swap endpoint: /chains/{chainId}/swap

Query

Description of query parameters

All parameters with asterisks * are REQUIRED.

Parameter name
Type
Description

chainId*

integer

Network chain ID of the target blockchain. Example: 42161 (Arbitrum).

tokenIn*

string

Contract address of the ERC20 token to swap from. Example: 0xaf88d065e77c8cC2239327C5EDb3A432268e5831 (USDC on Arbitrum).

tokenOut*

string

Contract address of the ERC20 token to swap to. Example: 0x82aF49447D8a07e3bd95BD0d56f35241523fBab1 (WETH on Arbitrum).

amountIn*

integer

Amount of tokenIn to sell, in minimal divisible units. Example: 1.00 USDC1000000

maxSlippage

float

Maximum acceptable slippage (percentage). Default: 0.5 (e.g. 0.5 = 0.5%).

fromAddress*

string

Address executing the swap transaction.

toAddress

string

Optional recipient address of the output tokens. If omitted, defaults to fromAddress.

deadline

integer

Optional Unix timestamp after which the swap is invalid. Defaults to 30 minutes from now.

Example request

HTTP GET

GET /chains/42161/swap?tokenIn=0xaf88d065e77c8cC2239327C5EDb3A432268e5831&tokenOut=0x82aF49447D8a07e3bd95BD0d56f35241523fBab1&amountIn=500000000&maxSlippage=0.5&fromAddress=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266

curl

curl -X GET "https://swap-api.nabla.fi/chains/42161/swap?tokenIn=0xaf88d065e77c8cC2239327C5EDb3A432268e5831&tokenOut=0x82aF49447D8a07e3bd95BD0d56f35241523fBab1&amountIn=500000000&maxSlippage=0.5&fromAddress=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266" \
  -H "accept: application/json"

Response

Response fields

Field
Type
Description

chainId

integer

Network chain ID.

tokenIn

string

Contract address of the input token (ERC20).

tokenOut

string

Contract address of the output token (ERC20).

amountIn

integer

Amount of tokenIn to sell (in minimal divisible units).

maxSlippage

float

Maximum acceptable slippage for this swap (percentage).

fromAddress

string

Address initiating the swap transaction.

toAddress

string

Recipient address of the output tokens.

deadline

integer

Unix timestamp after which the swap is invalid.

amountOut

integer

Estimated amount of output tokens to receive (in minimal divisible units).

estimatedSlippage

float

Estimated slippage for this swap, in percent.

amountOutMin

integer

Minimum amount of output tokens guaranteed to be received (in minimal divisible units).

routerPath

array[string]

Ordered list of NablaRouter addresses used in the route.

tokenPath

array[string]

Ordered list of token addresses used in the route.

tx

object

Transaction data object to execute the swap (includes to, data, value, etc.).

Example response

{
  "chainId": 42161,
  "tokenIn": "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
  "tokenOut": "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
  "amountIn": 500000000,
  "maxSlippage": 0.5,
  "fromAddress": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
  "toAddress": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
  "deadline": 1760439036,
  "amountOut": 126612259354618762,
  "estimatedSlippage": 0.0302,
  "amountOutMin": 125979198057845680,
  "routerPath": [
    "0x7bcFc8b8ff61456ad7C5E2be8517D01df006d18d"
  ],
  "tokenPath": [
    "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
    "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1"
  ],
  "tx": {
    "to": "0xcB94Eee869a2041F3B44da423F78134aFb6b676B",
    "data": "0xabcdef1234...",
    "value": "0",
    "gas": null,
    "gasPrice": null
  }
}

Notes

  • This endpoint generates calldata for an on-chain swap but does not execute the transaction.

  • The returned tx object can be directly passed to a wallet or smart contract for execution.

  • Prices and slippage are estimated at the time of request — execute the transaction promptly for best accuracy.

  • Use maxSlippage to define your tolerance against price movement before swap execution.

Last updated