GET /swap/quote

🔹 Get Swap Quote

🌐 Endpoint

GET https://client.deframe.io/v1/swap/quote

📝 Overview

Retrieve a quote for token swaps across different chains (intra-chain and cross-chain). This endpoint supports both same-chain and cross-chain token swaps by automatically detecting the swap type and routing to the appropriate provider.

🔑 Authentication

This API requires authentication using an API key. Include your API key in the request headers:

x-api-key: YOUR_API_KEY

📋 Query Parameters

Parameter
Type
Required
Description

originChainId

string

Source chain ID (e.g., "1", "137", "56")

tokenIn

string

Contract address of the input token

amountIn

string

Amount of input tokens to swap

destinationChainId

string

Target chain ID (e.g., "1", "137", "56")

tokenOut

string

Contract address of the output token

walletAddress

string

User's wallet address for provider-specific logic

decimalsIn

string

Number of decimals for the input token (auto-converted to number)

📦 Response

Returns a JSON object containing:

  • quote: Object containing swap quote details:

    • fromChain: Source chain information

    • toChain: Destination chain information

    • expectedAmountOut: Expected amount of output tokens

    • provider: Name of the swap provider used

    • Additional provider-specific fields may be included

Example Response:

{
  "quote": {
    "fromChain": {
      "chainId": "1",
      "name": "Ethereum"
    },
    "toChain": {
      "chainId": "137", 
      "name": "Polygon"
    },
    "expectedAmountOut": "1000000000000000000",
    "provider": "1inch",
    "tokenIn": "0xA0b86a33E6441b8c4C8C1C1B8c4C8C1C1B8c4C8C1",
    "tokenOut": "0xB0b86a33E6441b8c4C8C1C1B8c4C8C1C1B8c4C8C1",
    "amountIn": "500000000000000000"
  }
}

🔄 Swap Types

The endpoint automatically detects the swap type based on the chain IDs:

  • Intra-chain Swap: When originChainId equals destinationChainId

  • Cross-chain Swap: When originChainId differs from destinationChainId

🛠️ Error Handling

The API returns appropriate error messages for:

  • Missing required parameters

  • Invalid chain IDs or token addresses

  • No available swap provider for the requested route

  • Provider-specific errors during quote generation

Example Error Response:

{
  "error": "Failed to fetch quote: No provider available for: cross-chain from 1 to 999"
}

📝 Usage Examples

Intra-chain Swap (Ethereum USDT to USDC):

GET /swap/quote?originChainId=1&destinationChainId=1&tokenIn=0xdAC17F958D2ee523a2206206994597C13D831ec7&tokenOut=0xA0b86a33E6441b8c4C8C1C1B8c4C8C1C1B8c4C8C1&amountIn=1000000&walletAddress=0x123...

Cross-chain Swap (Ethereum to Polygon):

GET /swap/quote?originChainId=1&destinationChainId=137&tokenIn=0xdAC17F958D2ee523a2206206994597C13D831ec7&tokenOut=0xB0b86a33E6441b8c4C8C1C1B8c4C8C1C1B8c4C8C1&amountIn=1000000&decimalsIn=6

Last updated