swap

Get swap and bridge quotes

Changed on

Returns quotes from several liquidity sources for a same-chain swap or a cross-chain bridge between two tokens. Supports EVM chains and Solana, including EVM ↔ Solana bridges.

Liquidity sources. Each quote comes from one DEX, aggregator or bridge, named by liquidity_source in the response. Supported sources include 0x Exchange, 1inch, Bungee, Jupiter, KyberSwap, LI.FI, Relay, Uniswap and Velora. The set changes over time, so read liquidity_source.id from the response instead of hardcoding source names.

Quotes are sorted best first, in descending order of the fiat value of output_amount_after_fees: the output amount minus network, protocol and bridge fees not already included in the rate. Ties are broken alphabetically by liquidity_source.id, so identical requests always return quotes in the same order.

input and output are objects encoded with bracket notation, so the request is a flat query string. For example:

GET /v1/swap/quotes/?currency=usd&input[chain_id]=base&input[fungible_id]=0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2&input[amount]=0.001&output[fungible_id]=0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48&from=0xd8da6bf26964af9d7eed9e03e53415d37aa96045&to=0xd8da6bf26964af9d7eed9e03e53415d37aa96045
get/v1/swap/quotes/

Request

  • Base URL
    https://api.zerion.io
  • URL
    https://api.zerion.io/v1/swap/quotes/
  • Auth
    HTTP basic

Query parameters

currencystring

Currency for the fiat values of amounts and fees in the response. Defaults to usd.

fromstring required

Wallet address making the swap. Must match the chain type of input[chain_id] (EVM hex or Solana base58).

tostring required

Recipient of the output asset. Must match the chain type of output[chain_id]. For a same-chain swap to the same wallet, set to equal to from.

chain_idstring required

Chain ID the input asset lives on.

fungible_idstring required

Fungible ID of the input asset.

amountstring required

Human-readable input amount as a positive decimal (not in the smallest unit).

The asset to send.

{
  "chain_id": "base",
  "fungible_id": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
  "amount": "0.001"
}
chain_idstring

Chain ID the output asset lives on. Defaults to input[chain_id] (same-chain swap).

fungible_idstring required

Fungible ID of the output asset.

The asset to receive.

{
  "chain_id": "base",
  "fungible_id": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"
}
slippage_percentnumber float

Maximum acceptable slippage, in percent. If omitted, the API picks an automatic slippage value.

Response

Response for the requested swap quotes.

Example response

{
  "links": {
    "self": "https://api.zerion.io/v1/wallet/0x42b9df65b219b3dd36ff330a4dd8f327a6ada990/swap-list"
  },
  "data": [
    {
      "type": "swap_quotes",
      "id": "589a0095e2111df5276ebf073fff9a8bfb821f34",
      "attributes": {
        "liquidity_source": {
          "id": "relay",
          "name": "Relay",
          "icon": {
            "url": "https://token-icons.s3.amazonaws.com/0x0391d2021f89dc339f60fff84546ea23e337750f.png"
          }
        },
        "input_amount": {
          "quantity": "0.001",
          "value": 2.2830463441233997,
          "usd_value": 2.2830463441233997,
          "currency": "USD"
        },
        "output_amount": {
          "quantity": "0.001",
          "value": 2.2830463441233997,
          "usd_value": 2.2830463441233997,
          "currency": "USD"
        },
        "minimum_output_amount": {
          "quantity": "0.001",
          "value": 2.2830463441233997,
          "usd_value": 2.2830463441233997,
          "currency": "USD"
        },
        "output_amount_after_fees": {
          "quantity": "0.001",
          "value": 2.2830463441233997,
          "usd_value": 2.2830463441233997,
          "currency": "USD"
        },
        "rate": [
          {
            "value": 1,
            "symbol": "WETH"
          }
        ],
        "slippage_percent": 2,
        "protocol_fee": {
          "amount": {
            "quantity": "0.001",
            "value": 2.2830463441233997,
            "usd_value": 2.2830463441233997,
            "currency": "USD"
          },
          "fungible": {
            "type": "fungibles",
            "id": "eth"
          },
          "base_percentage": 0.67
        },
        "bridge_fee": {
          "amount": {
            "quantity": "0.001",
            "value": 2.2830463441233997,
            "usd_value": 2.2830463441233997,
            "currency": "USD"
          },
          "fungible": {
            "type": "fungibles",
            "id": "eth"
          },
          "included_in_rate": true
        },
        "network_fee": {
          "amount": {
            "quantity": "0.001",
            "value": 2.2830463441233997,
            "usd_value": 2.2830463441233997,
            "currency": "USD"
          },
          "fungible": {
            "type": "fungibles",
            "id": "eth"
          }
        },
        "transaction_approve": {
          "evm": {
            "type": "0x2",
            "from": "0xbf9db3564c22fd22ff30a8db7f689d654bf5f1fd",
            "to": "0xb2be281e8b11b47fec825973fc8bb95332022a54",
            "nonce": "0x42",
            "chain_id": "0x1",
            "gas": "0x1c138",
            "gas_price": "0x9502f900",
            "max_fee": "0xc6a17141",
            "max_priority_fee": "0x35aeb151",
            "value": "0x0",
            "data": "0xa9059cbb000000000000000000000000d8da6bf26964af9d7eed9e03e53415d37aa9604500000000000000000000000000000000000000000000000000000000000003e8"
          }
        },
        "transaction_swap": {
          "evm": {
            "type": "0x2",
            "from": "0xbf9db3564c22fd22ff30a8db7f689d654bf5f1fd",
            "to": "0xb2be281e8b11b47fec825973fc8bb95332022a54",
            "nonce": "0x42",
            "chain_id": "0x1",
            "gas": "0x1c138",
            "gas_price": "0x9502f900",
            "max_fee": "0xc6a17141",
            "max_priority_fee": "0x35aeb151",
            "value": "0x0",
            "data": "0xa9059cbb000000000000000000000000d8da6bf26964af9d7eed9e03e53415d37aa9604500000000000000000000000000000000000000000000000000000000000003e8"
          }
        },
        "error": {
          "code": "not_enough_input_asset_balance",
          "message": "Input asset balance is not enough to execute a swap",
          "hint": "topup"
        },
        "estimated_time_seconds": 2
      },
      "relationships": {
        "input_chain": {
          "links": {
            "related": "https://api.zerion.io/v1/chains/polygon"
          },
          "data": {
            "type": "chains",
            "id": "polygon"
          }
        },
        "output_chain": {
          "links": {
            "related": "https://api.zerion.io/v1/chains/polygon"
          },
          "data": {
            "type": "chains",
            "id": "polygon"
          }
        },
        "input_fungible": {
          "links": {
            "related": "https://api.zerion.io/v1/fungibles/eth"
          },
          "data": {
            "type": "fungibles",
            "id": "eth"
          }
        },
        "output_fungible": {
          "links": {
            "related": "https://api.zerion.io/v1/fungibles/eth"
          },
          "data": {
            "type": "fungibles",
            "id": "eth"
          }
        }
      }
    }
  ]
}

Changes

    • warning

      added the new add_wallet enum value to the //// response property for the response status

    • warning

      added the new no_wallet enum value to the //// response property for the response status

    • info

      removed the increase_input_amount enum value from the //// response property for the response status

    • info

      removed the input_amount_is_too_small enum value from the //// response property for the response status

    • breaking

      added the new required query request parameter from

    • breaking

      added the new required query request parameter input

    • breaking

      added the new required query request parameter output

    • breaking

      added the new required query request parameter to

    • info

      api operation id swapQuotes was added

    • info

      added the new optional query request parameter currency

    • info

      added the new optional query request parameter slippage_percent

    • info

      added the non-success response with the status

    • info

      added the non-success response with the status

    • info

      added the non-success response with the status

    • info

      added the success response with the status