How to get a quote
In this section, you'll learn how to request quotes for swapping between tokens using the DeFrame API.
Prerequisites
API key for authentication
Token contract addresses for the tokens you want to swap
Chain IDs for source and destination chains
Overview
The DeFrame API supports both intra-chain and cross-chain token swaps. The system automatically detects the swap type based on the chain IDs provided and routes to the appropriate provider.
Authentication
All requests require an API key in the headers:
x-api-key: YOUR_API_KEY
Getting a Quote
Endpoint
GET https://client.deframe.io/v1/swap/quote
Required Parameters
originChainId
string
Source chain ID
"1"
(Ethereum), "137"
(Polygon), "56"
(BSC)
tokenIn
string
Contract address of input token
"0xdAC17F958D2ee523a2206206994597C13D831ec7"
(USDT)
amountIn
string
Amount of input tokens to swap
"1000000"
(1 USDT with 6 decimals)
destinationChainId
string
Target chain ID
"137"
(Polygon)
tokenOut
string
Contract address of output token
"0xA0b86a33E6441b8c4C8C1C1B8c4C8C1C1B8c4C8C1"
Optional Parameters
walletAddress
string
User's wallet address for provider-specific logic
"0x1234567890123456789012345678901234567890"
decimalsIn
string
Number of decimals for input token
"6"
Example Requests
Intra-chain Swap (Ethereum USDT to USDC)
GET /swap/quote?originChainId=1&destinationChainId=1&tokenIn=0xdAC17F958D2ee523a2206206994597C13D831ec7&tokenOut=0xA0b86a33E6441b8c4C8C1C1B8c4C8C1C1B8c4C8C1&amountIn=1000000&walletAddress=0x1234567890123456789012345678901234567890
Cross-chain Swap (Ethereum to Polygon)
GET /swap/quote?originChainId=1&destinationChainId=137&tokenIn=0xdAC17F958D2ee523a2206206994597C13D831ec7&tokenOut=0xB0b86a33E6441b8c4C8C1C1B8c4C8C1C1B8c4C8C1&amountIn=1000000&decimalsIn=6
Response Format
The API returns a JSON object containing the quote details:
{
"quote": {
"fromChain": {
"chainId": "1",
"name": "Ethereum"
},
"toChain": {
"chainId": "137",
"name": "Polygon"
},
"expectedAmountOut": "1000000000000000000",
"provider": "1inch",
"tokenIn": "0xA0b86a33E6441b8c4C8C1C1B8c4C8C1C1B8c4C8C1",
"tokenOut": "0xB0b86a33E6441b8c4C8C1C1B8c4C8C1C1B8c4C8C1",
"amountIn": "500000000000000000"
}
}
Response Fields
fromChain
: Source chain information (chainId, name)toChain
: Destination chain information (chainId, name)expectedAmountOut
: Expected amount of output tokensprovider
: Name of the swap provider used (e.g., "1inch", "socket")tokenIn
: Input token contract addresstokenOut
: Output token contract addressamountIn
: Input amount
Swap Types
The API automatically detects the swap type:
Intra-chain Swap: When
originChainId
equalsdestinationChainId
Cross-chain Swap: When
originChainId
differs fromdestinationChainId
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"
}
Next Steps
After getting a quote, you can:
Last updated