Comment on page
Quote & Swap APIs
Get the best single-step route for swapping X to Y
Using the quote method, you can get a preview of the best route for this cross-chain swap. It goes through all the possible DEXs, bridges and aggregators to find the best possible single-step route based on user experience, fee amount, and swap output.
Typescript
cURL
const quoteResponse = await rangoClient.quote({
from: {"blockchain": "BSC", "symbol": "BNB", "address": null},
to: {"blockchain": "AVAX_CCHAIN", "symbol": "USDT.E", "address": "0xc7198437980c041c805a1edcba50c1ce5db95118"},
amount: "100000000000000000" // 0.1 BSC.BNB
})
curl --request GET \
--url 'https://api.rango.exchange/basic/quote?from=BSC.BNB&to=AVAX_CCHAIN.USDT.E--0xc7198437980c041c805a1edcba50c1ce5db95118&amount=100000000000000000&apiKey=c6381a79-2817-4602-83bf-6a641a409e32' \
--header 'accept: */*'
Quote (Get Best Route)
rango-exchange
Get Quote Swagger Link
Param | Description |
---|---|
from * | The source asset |
to * | The destination asset |
amount * | The big number amount (machine readable) of asset X that is going to be swapped, e.g. 100000000000000000000 for 100 Fantom.FTM |
slippage | Amount of user's preferred slippage in percent. if you don't send it, it will assume 0.5% slippage. (It's used to filter the swappers or routes that are not suitable for the given slippage) |
swappers | List of all accepted swappers, an empty list means no filter is required. |
swappersExclude | Defines the provided swappers as the include/exclude list. Default is false (include) |
swapperGroups | The list of all included/excluded swappers based on tag, empty list means no filter is required |
swappersGroupsExclude | Defines the provided swappers' tags as the include/exclude list. Default is false (include) |
contractCall | important: set this parameter to true if you want to send transactions through a contract. It will filter swappers that are not possible to be called by another contract. |
sourceContract | Address of your contract on source chain (will be called in case of refund in the source chain) |
destinationContract | Address of your contract on destination chain (will be called in case of success/refund in the destination chain) |
messagingProtocols | Message protocols which will be used to relay message in a cross-chain swap. An empty list means no filter is required. |
imMessage | The message that you want to pass to your contract on the destination chain |
referrerFee | Referrer fee in percent |
Field | Description |
---|---|
requestId | The unique request Id which is generated for this request by the server. It should be passed down to all other endpoints if this swap continues on. e.g. d10657ce-b13a-405c-825b-b47f8a5016ad |
resultType | Status of the route: OK , HIGH_IMPACT , INPUT_LIMIT_ISSUE , NO_ROUTE |
route | The quote route object |
Based on
resultType
field, you could decide if the quote response is valid or need to show a proper message to the user (or retry). Possible values for this field are OK
, HIGH_IMPACT
, INPUT_LIMIT_ISSUE
and NO_ROUTE
.resultType | Reason |
---|---|
OK | Best route found. Everything is OK. |
HIGH_IMPACT | If the best route has a high price impact, we recommend not proceeding with the next step (swap). The Rango API may give you an error in the next step to prevent potential losses. |
INPUT_LIMIT_ISSUE | There is a limit issue for the input amount. You could suggest user increase/decrease the input amount based on amountRestrictions field in response. |
NO_ROUTE | No routes found. |
The
route.amountRestriction
field indicates the minimum and maximum possible input amount for this quote. EXCLUSIVE
field means that min<input<max
and INCLUSIVE
means min<=input<=max
.These are two possible types of fees (
expenseType
field in the route.fee
array). expenseType | Description |
---|---|
FROM_SOURCE_WALLET | The gas fee. This fee should be available in the user's wallet for the swap to succeed. |
DECREASE_FROM_OUTPUT | Some hidden fees in swapper which will be reduced from the user's output amount automatically. This fee is already calculated in the estimated output. |
It's similar to the quote method but gives the actual transaction data in response besides the route.
Typescript
cURL
const swapResponse = await rangoClient.swap({
from: {"blockchain": "BSC", "symbol": "BNB", "address": null},
to: {"blockchain": "AVAX_CCHAIN", "symbol": "USDT.E", "address": "0xc7198437980c041c805a1edcba50c1ce5db95118"},
amount: "100000000000000000" // 0.1 BSC.BNB3
fromAddress: "0xeb2629a2734e272bcc07bda959863f316f4bd4cf",
toAddress: "0xeb2629a2734e272bcc07bda959863f316f4bd4cf",
disableEstimate: true,
slippage: '1.0',
})
curl --request GET \
--url 'https://api.rango.exchange/basic/swap?from=BSC.BNB&to=AVAX_CCHAIN.USDT.E--0xc7198437980c041c805a1edcba50c1ce5db95118&amount=100000000000000000&slippage=3&swappers=&fromAddress=0x6f33bb1763eebead07cf8815a62fcd7b30311fa3&toAddress=0x6f33bb1763eebead07cf8815a62fcd7b30311fa3&apiKey=c6381a79-2817-4602-83bf-6a641a409e32' \
--header 'accept: */*'
Swap (Create Transaction)
rango-exchange
Swap Swagger Link
Param | Description |
---|---|
from * | The asset X that user likes to swap |
to * | The asset Y that user wants to swap X into that |
amount * | The machine-readable amount of asset X that is going to be swapped |
slippage * | User slippage for this swap (e.g. 1.5 which means 1.5% slippage) |
fromAddress * | User source wallet address |
toAddress * | User destination wallet address |
disableEstimate | This field should be false when the client wants to preview the route to the user and true when the user accepts the swap. If it's true, the server will be much slower to respond but will check some prerequisites, including the balance of X and any required fees in the user's wallets.
Important: If you are checking the balance and fee amount on your client side, it's recommended to pass this param as true. |
referrerAddress | Referrer wallet address |
referrerFee | Referrer fee in percent, (e.g. 0.3 means: 0.3% fee based on input amount) |
swappers | List of all accepted swappers, an empty list means no filter is required. |
swappersExclude | Defines the provided swappers as the include/exclude list. Default is false (include) |
swapperGroups | The list of all included/excluded swappers based on tag, empty list means no filter is required |
swappersGroupsExclude | Defines the provided swappers' tags as the include/exclude list. Default is false (include) |
messagingProtocols | List of all messaging protocols, an empty list means no filter is required. |
infiniteApprove | Use this parameter if you want infinite approve from user |
contractCall | important: set this parameter to true if you want to send transactions through a contract. It will filter swappers that are not possible to be called by another contract. |
sourceContract | Address of your contract on source chain (will be called in case of refund in the source chain) |
destinationContract | Address of your contract on destination chain (will be called in case of success/refund in the destination chain) |
imMessage | The message that you want to pass to your contract on the destination chain |
Field | Description |
---|---|
requestId | The unique request Id which is generated for this request by the server. It should be passed down to all other endpoints if this swap continues on. e.g. d10657ce-b13a-405c-825b-b47f8a5016ad |
resultType | Status of the route, possible values are: OK , HIGH_IMPACT , INPUT_LIMIT_ISSUE , NO_ROUTE.
Important: This is the status of route same as the quote response. If there was any error in creating tx, it will be appear in error field. So you could check (error !== null) && (status === 'OK') to make sure everything is ok before proceeding with the next step. |
route | The quote route object. Similar to the quote response. |
error | Error message (raw string) if there is any problem in creating transaction. (error === null <=> tx !== null) |
tx | Transaction data for this route. |
Check this link to see an example of transaction data:
Last modified 3mo ago