2⃣
Quote
Get the best route to swap X to Y
Using information retrieved from the meta, you could implement your own SwapBox including your blockchain and token selector. The next step is to show the preview of the best route possible when the user selects the source and the destination tokens.
Typescript
cURL
// Converting 0.1 BSC BNB to AVAX_CCHAIN USDT.E
const quote = await rangoClient.quote({
from: {
"blockchain": "BSC",
"symbol": "BNB",
"address": null
},
to: {
"blockchain": "AVAX_CCHAIN",
"symbol": "USDT.E",
"address": "0xc7198437980c041c805a1edcba50c1ce5db95118"
},
amount: "100000000000000000"
})
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: */*'
The blockchain and symbol names must be exactly what is fetched from Rango's metadata APIs. Check Metadata and Blockchains Metadata APIs regarding this.
You could call this method periodically to get the updated route before the user confirms the swap.
Please check this doc if you want to get complete details on important fields in the quote response including
resultType
, fee
and amountRestriction
.Here is a sample quote object you could get.
sample quote
1
{{
2
"requestId": "a64f4851-f61f-4407-86c5-e37abd289d99",
3
"resultType": "OK",
4
"route": {
5
"outputAmount": "24307447",
6
"outputAmountMin": "24064980",
7
"outputAmountUsd": 24.304634664703492,
8
"swapper": {
9
"id": "Hyphen Aggregator",
10
"title": "Hyphen",
11
"logo": "https://api.rango.exchange/swappers/hyphen.svg",
12
"swapperGroup": "Hyphen",
13
"types": [
14
"AGGREGATOR"
15
],
16
"enabled": true
17
},
18
"from": {
19
"blockchain": "BSC",
20
"symbol": "BNB",
21
"name": null,
22
"isPopular": false,
23
"chainId": "56",
24
"address": null,
25
"decimals": 18,
26
"image": "https://api.rango.exchange/tokens/ETH/BNB.png",
27
"blockchainImage": "https://api.rango.exchange/blockchains/bsc.svg",
28
"usdPrice": 243.71759113601925,
29
"supportedSwappers": []
30
},
31
"to": {
32
"blockchain": "AVAX_CCHAIN",
33
"symbol": "USDT.E",
34
"name": null,
35
"isPopular": false,
36
"chainId": "43114",
37
"address": "0xc7198437980c041c805a1edcba50c1ce5db95118",
38
"decimals": 6,
39
"image": "https://api.rango.exchange/i/niIihm",
40
"blockchainImage": "https://api.rango.exchange/blockchains/avax_cchain.svg",
41
"usdPrice": 0.9998843014942496,
42
"supportedSwappers": []
43
},
44
"fee": [
45
{
46
"token": {
47
"blockchain": "BSC",
48
"symbol": "BNB",
49
"name": null,
50
"isPopular": true,
51
"chainId": "56",
52
"address": null,
53
"decimals": 18,
54
"image": "https://api.rango.exchange/tokens/ETH/BNB.png",
55
"blockchainImage": "https://api.rango.exchange/blockchains/bsc.svg",
56
"usdPrice": 243.71759113601925,
57
"supportedSwappers": [
58
"Wormhole",
59
"ParaSwap Bsc",
60
"OneInchBsc",
61
"Satellite",
62
"PancakeSwapBsc",
63
"Voyager",
64
"cBridge v2.0"
65
]
66
},
67
"expenseType": "FROM_SOURCE_WALLET",
68
"amount": "1037163600000000",
69
"name": "Network Fee"
70
}
71
],
72
"feeUsd": 0.2527750142059618,
73
"amountRestriction": {
74
"min": "42359934341395595",
75
"max": "239354192103808110634",
76
"type": "EXCLUSIVE"
77
},
78
"estimatedTimeInSeconds": 75,
79
"path": [
80
{
81
"swapper": {
82
"id": "OneInchBsc",
83
"title": "1Inch",
84
"logo": "https://api.rango.exchange/swappers/1inch.svg",
85
"swapperGroup": "1Inch",
86
"types": [
87
"DEX"
88
],
89
"enabled": true
90
},
91
"swapperType": "DEX",
92
"from": {
93
"blockchain": "BSC",
94
"symbol": "BNB",
95
"name": null,
96
"isPopular": false,
97
"chainId": "56",
98
"address": null,
99
"decimals": 18,
100
"image": "https://api.rango.exchange/tokens/ETH/BNB.png",
101
"blockchainImage": "https://api.rango.exchange/blockchains/bsc.svg",
102
"usdPrice": 243.71759113601925,
103
"supportedSwappers": []
104
},
105
"to": {
106
"blockchain": "BSC",
107
"symbol": "USDT",
108
"name": null,
109
"isPopular": false,
110
"chainId": "56",
111
"address": "0x55d398326f99059ff775485246999027b3197955",
112
"decimals": 18,
113
"image": "https://tokens.1inch.io/0xdac17f958d2ee523a2206206994597c13d831ec7.png",
114
"blockchainImage": "https://api.rango.exchange/blockchains/bsc.svg",
115
"usdPrice": 0.999613,
116
"supportedSwappers": []
117
},
118
"inputAmount": "99989999999999999",
119
"expectedOutput": "24312998025437187460",
120
"estimatedTimeInSeconds": 15
121
},
122
{
123
"swapper": {
124
"id": "Hyphen",
125
"title": "Hyphen",
126
"logo": "https://api.rango.exchange/swappers/hyphen.svg",
127
"swapperGroup": "Hyphen",
128
"types": [
129
"BRIDGE"
130
],
131
"enabled": true
132
},
133
"swapperType": "BRIDGE",
134
"from": {
135
"blockchain": "BSC",
136
"symbol": "USDT",
137
"name": null,
138
"isPopular": false,
139
"chainId": "56",
140
"address": "0x55d398326f99059ff775485246999027b3197955",
141
"decimals": 18,
142
"image": "https://biconomy-public-assets.s3.amazonaws.com/tokens/usdt-icon.svg",
143
"blockchainImage": "https://api.rango.exchange/blockchains/bsc.svg",
144
"usdPrice": 0.999613,
145
"supportedSwappers": []
146
},
147
"to": {
148
"blockchain": "AVAX_CCHAIN",
149
"symbol": "USDT.E",
150
"name": null,
151
"isPopular": false,
152
"chainId": "43114",
153
"address": "0xc7198437980c041c805a1edcba50c1ce5db95118",
154
"decimals": 6,
155
"image": "https://api.rango.exchange/i/niIihm",
156
"blockchainImage": "https://api.rango.exchange/blockchains/avax_cchain.svg",
157
"usdPrice": 0.9998843014942496,
158
"supportedSwappers": []
159
},
160
"inputAmount": "24312998025437187460",
161
"expectedOutput": "24307447",
162
"estimatedTimeInSeconds": 60
163
}
164
]
165
},
166
"error": null
167
}
Last modified 1mo ago