@pioneer-platform/swapkit-client 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/README.md +159 -0
- package/docs/docs.md +1508 -0
- package/lib/index.d.ts +81 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +271 -0
- package/lib/index.js.map +1 -0
- package/package.json +30 -0
- package/test-arb-amount.js +47 -0
- package/test-various-routes.js +60 -0
- package/tsconfig.json +20 -0
package/docs/docs.md
ADDED
|
@@ -0,0 +1,1508 @@
|
|
|
1
|
+
# Introduction
|
|
2
|
+
|
|
3
|
+
Our API aggregates several key providers and protocols, offering access to an extensive range of chains and tokens without the complexity of managing multiple integrations. It is designed to integrate cross-chain swaps into your application with ease in addition to in-chain dex aggregation for single-chain swaps.
|
|
4
|
+
|
|
5
|
+
### How to use SwapKit's API
|
|
6
|
+
|
|
7
|
+
To get the most out of SwapKit's API we recommend going through the endpoints in the following order:
|
|
8
|
+
|
|
9
|
+
1. **`/providers`** – Retrieve a list of available providers and their supported chains.
|
|
10
|
+
2. **`/tokens`** – Fetch a list of supported tokens across different chains and providers.
|
|
11
|
+
3. **`/quote`** – Request a swap quote to estimate the cost and parameters for a transaction.
|
|
12
|
+
4. **`/track`** – Track the status of a swap to monitor its progress and completion.
|
|
13
|
+
|
|
14
|
+
However, `/providers` and `/tokens` don't change often, and you can directly request a quote once you have everything set up.\
|
|
15
|
+
Additionally, the `/screen` endpoint can be used to validate AML compliance of the involved addresses. If it is something you need, use it before the transaction is offered for signing and not with every `/quote`.\
|
|
16
|
+
You can try the API yourself at <https://api.swapkit.dev/docs/> . \
|
|
17
|
+
You can also check out our transaction tracking interface at <https://track.swapkit.dev/>.\
|
|
18
|
+
Please read over our recommended [quote implementation flow](https://docs.swapkit.dev/swapkit-api/quote-implementation-flow) to understand how to create a better performing integration.
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
# Swap Types
|
|
22
|
+
|
|
23
|
+
SwapKit supports three distinct swap mechanisms, each serving different use cases and offering unique advantages.
|
|
24
|
+
|
|
25
|
+
### Cross-Chain Swaps
|
|
26
|
+
|
|
27
|
+
Cross-chain swaps enable direct asset exchanges between different blockchain networks in a single transaction. These swaps are powered by specialized cross-chain protocols that act as bridges between otherwise isolated blockchains and cover the major tokens on those chains.
|
|
28
|
+
|
|
29
|
+
#### Available Providers
|
|
30
|
+
|
|
31
|
+
SwapKit integrates with four major cross-chain swap providers:
|
|
32
|
+
|
|
33
|
+
* THORChain
|
|
34
|
+
* NEAR
|
|
35
|
+
* Chainflip
|
|
36
|
+
* Maya Chain
|
|
37
|
+
|
|
38
|
+
Each provider offers different chain coverage, you can see more information on this [here](https://docs.swapkit.dev/swapkits-trade-offerings).
|
|
39
|
+
|
|
40
|
+
### Single-Chain Swaps
|
|
41
|
+
|
|
42
|
+
Single-chain swaps occur within a single blockchain ecosystem, leveraging decentralized exchanges (DEXs) and aggregators to find the best rates for token swaps on that specific chain.
|
|
43
|
+
|
|
44
|
+
#### Current Provider
|
|
45
|
+
|
|
46
|
+
* 1inch, available on:
|
|
47
|
+
* Ethereum (ETH)
|
|
48
|
+
* Avalanche (AVAX)
|
|
49
|
+
* Arbitrum (ARB)
|
|
50
|
+
* BNB Smart Chain (BSC)
|
|
51
|
+
* Jupiter, available on Solana (SOL)
|
|
52
|
+
|
|
53
|
+
For a complete list of supported tokens on each chain, query the `/tokens` endpoint.
|
|
54
|
+
|
|
55
|
+
### Cross-Chain DEX Aggregation
|
|
56
|
+
|
|
57
|
+
Some tokens other than the gas assets like ETH, BNB or AVAX are available through our cross-chain providers, but others like most alt-coins are not. Cross-chain DEX aggregation combines single-chain DEX aggregators with cross-chain protocols to access any token on supported chains. This is achieved through two mechanisms:
|
|
58
|
+
|
|
59
|
+
#### Swap Ins
|
|
60
|
+
|
|
61
|
+
Swap ins perform a single-chain swap followed by a cross-chain transfer. This allows users to swap from any token in the source chain into the major tokens in other supported chains.
|
|
62
|
+
|
|
63
|
+
Swap Ins are currently supported with the combination of 1inch + THORChain (with support for other providers coming soon).
|
|
64
|
+
|
|
65
|
+
**Supported Networks:** available for swaps initiated on networks where THORChain and 1inch overlap:
|
|
66
|
+
|
|
67
|
+
* Ethereum (ETH)
|
|
68
|
+
* Avalanche (AVAX)
|
|
69
|
+
* BNB Smart Chain (BSC)
|
|
70
|
+
|
|
71
|
+
Into any chain supported by THORChain.
|
|
72
|
+
|
|
73
|
+
#### Swap Outs
|
|
74
|
+
|
|
75
|
+
Swap outs perform the reverse operation, a cross-chain swap first followed by a single-chain swap on the destination chain.
|
|
76
|
+
|
|
77
|
+
**Current Status:** **Temporarily Disabled**
|
|
78
|
+
|
|
79
|
+
### Using the /quote Endpoint
|
|
80
|
+
|
|
81
|
+
The `/quote` endpoint intelligently routes your swaps through the appropriate providers based on the assets and chains involved.\
|
|
82
|
+
As you delve into our documentation, come back here to understand more about the logic behind integrating Cross-Chain DEX Aggregation.
|
|
83
|
+
|
|
84
|
+
#### Provider Selection
|
|
85
|
+
|
|
86
|
+
The `providers` parameter is **optional**. When not specified, the API will:
|
|
87
|
+
|
|
88
|
+
* Search all available routing paths
|
|
89
|
+
* Return the routes found
|
|
90
|
+
* Include the utilized providers in the response
|
|
91
|
+
|
|
92
|
+
If you specify the `providers` parameter but it's more restrictive than the available options, you'll receive an error:
|
|
93
|
+
|
|
94
|
+
```json
|
|
95
|
+
{
|
|
96
|
+
"error": "noRoutesFound",
|
|
97
|
+
"message": "No routes found for ETH.CRV-0xD533a949740bb3306d119CC777fa900bA034cd52 -> BTC.BTC",
|
|
98
|
+
"data": {
|
|
99
|
+
"sellAsset": "ETH.CRV-0xD533a949740bb3306d119CC777fa900bA034cd52",
|
|
100
|
+
"buyAsset": "BTC.BTC"
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
#### Transaction Data
|
|
106
|
+
|
|
107
|
+
Include `"includeTx": true` in your request to receive the transaction object needed to execute the swap. The response will include a `legs` array showing each step of the swap process. This example shows a swap-in transaction where:
|
|
108
|
+
|
|
109
|
+
1. First leg: 1inch converts CRV to ETH on Ethereum
|
|
110
|
+
2. Second leg: THORChain swaps ETH for Bitcoin
|
|
111
|
+
|
|
112
|
+
{% code overflow="wrap" %}
|
|
113
|
+
|
|
114
|
+
```json
|
|
115
|
+
"legs": [
|
|
116
|
+
{
|
|
117
|
+
"provider": "ONEINCH",
|
|
118
|
+
"sellAsset": "ETH.CRV-0xD533a949740bb3306d119CC777fa900bA034cd52",
|
|
119
|
+
"sellAmount": "2000",
|
|
120
|
+
"buyAsset": "ETH.ETH",
|
|
121
|
+
"buyAmount": "0.500852152196543104",
|
|
122
|
+
"buyAmountMaxSlippage": "0.490835109152612241",
|
|
123
|
+
"fees": [
|
|
124
|
+
{
|
|
125
|
+
"type": "inbound",
|
|
126
|
+
"amount": "0.000251000795472595",
|
|
127
|
+
"asset": "ETH.ETH",
|
|
128
|
+
"chain": "ETH",
|
|
129
|
+
"protocol": "ONEINCH"
|
|
130
|
+
}
|
|
131
|
+
]
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
"provider": "THORCHAIN",
|
|
135
|
+
"sellAsset": "ETH.ETH",
|
|
136
|
+
"sellAmount": "0.500852152196543104",
|
|
137
|
+
"buyAsset": "BTC.BTC",
|
|
138
|
+
"buyAmount": "0.01564204",
|
|
139
|
+
"buyAmountMaxSlippage": "0.01532919",
|
|
140
|
+
"fees": [
|
|
141
|
+
{
|
|
142
|
+
"type": "liquidity",
|
|
143
|
+
"amount": "0.00001569",
|
|
144
|
+
"asset": "BTC.BTC",
|
|
145
|
+
"chain": "THOR",
|
|
146
|
+
"protocol": "THORCHAIN"
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
"type": "outbound",
|
|
150
|
+
"amount": "0.00000918",
|
|
151
|
+
"asset": "BTC.BTC",
|
|
152
|
+
"chain": "THOR",
|
|
153
|
+
"protocol": "THORCHAIN"
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
"type": "affiliate",
|
|
157
|
+
"amount": "0",
|
|
158
|
+
"asset": "BTC.BTC",
|
|
159
|
+
"chain": "THOR",
|
|
160
|
+
"protocol": "THORCHAIN"
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
"type": "service",
|
|
164
|
+
"amount": "0.00003137",
|
|
165
|
+
"asset": "BTC.BTC",
|
|
166
|
+
"chain": "THOR",
|
|
167
|
+
"protocol": "THORCHAIN"
|
|
168
|
+
}
|
|
169
|
+
]
|
|
170
|
+
}
|
|
171
|
+
],
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
{% endcode %}
|
|
175
|
+
|
|
176
|
+
# /providers - Request supported chains by a swap provider
|
|
177
|
+
|
|
178
|
+
The `/providers` endpoint allows users to retrieve a comprehensive list of all available swap providers integrated by SwapKit and their supported chains and metadata. This endpoint does not require any parameters and always returns the full list of providers and their information.
|
|
179
|
+
|
|
180
|
+
**Method:** `GET`\
|
|
181
|
+
**URL:** `https://api.swapkit.dev/providers`
|
|
182
|
+
|
|
183
|
+
**Request example:**
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
curl -X 'GET' \
|
|
187
|
+
'https://api.swapkit.dev/providers' \
|
|
188
|
+
-H 'accept: application/json' \
|
|
189
|
+
-H "x-api-key: YOUR_VARIABLE_HERE"
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
***
|
|
193
|
+
|
|
194
|
+
### Response structure
|
|
195
|
+
|
|
196
|
+
The response contains an array of provider objects. Each object includes the following fields:
|
|
197
|
+
|
|
198
|
+
* `name` and `provider`: The name of the provider, used by SwapKit to reference it.
|
|
199
|
+
* `keywords`: Relevant keywords for the provider.
|
|
200
|
+
* `count`: Number of supported tokens.
|
|
201
|
+
* `logoURI`: URL to the provider’s logo.
|
|
202
|
+
* `url`: URL to the provider’s token list.
|
|
203
|
+
* `supportedChainIds`: List of supported chain IDs for the provider.
|
|
204
|
+
|
|
205
|
+
#### Sample provider information
|
|
206
|
+
|
|
207
|
+
```json
|
|
208
|
+
[
|
|
209
|
+
{
|
|
210
|
+
"name": "CHAINFLIP_STREAMING",
|
|
211
|
+
"provider": "CHAINFLIP_STREAMING",
|
|
212
|
+
"keywords": [],
|
|
213
|
+
"count": 10,
|
|
214
|
+
"logoURI": "https://storage.googleapis.com/token-list-swapkit/images/eth.flip-0x826180541412d574cf1336d22c0c0a287822678a.png",
|
|
215
|
+
"url": "https://storage.googleapis.com/token-list-swapkit/chainflip_streaming.json",
|
|
216
|
+
"supportedActions": [
|
|
217
|
+
"swap"
|
|
218
|
+
],
|
|
219
|
+
"supportedChainIds": [
|
|
220
|
+
"42161",
|
|
221
|
+
"bitcoin",
|
|
222
|
+
"1",
|
|
223
|
+
"solana"
|
|
224
|
+
]
|
|
225
|
+
},
|
|
226
|
+
...
|
|
227
|
+
]
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
***
|
|
231
|
+
|
|
232
|
+
### Supported providers
|
|
233
|
+
|
|
234
|
+
Below is the list of all providers available in the `/providers` response:
|
|
235
|
+
|
|
236
|
+
```json
|
|
237
|
+
[
|
|
238
|
+
"THORCHAIN",
|
|
239
|
+
"THORCHAIN_STREAMING",
|
|
240
|
+
"CHAINFLIP",
|
|
241
|
+
"CHAINFLIP_STREAMING",
|
|
242
|
+
"MAYACHAIN",
|
|
243
|
+
"MAYACHAIN_STREAMING",
|
|
244
|
+
"NEAR",
|
|
245
|
+
"ONEINCH",
|
|
246
|
+
"PANCAKESWAP",
|
|
247
|
+
"TRADERJOE_V2",
|
|
248
|
+
"UNISWAP_V2",
|
|
249
|
+
"UNISWAP_V3",
|
|
250
|
+
"CAVIAR_V1",
|
|
251
|
+
"JUPITER",
|
|
252
|
+
"CAMELOT_V3"
|
|
253
|
+
]
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
{% hint style="info" %}
|
|
257
|
+
The Streaming providers split the transaction over time. Transactions take longer to execute but have better pricing, so they offer an overall better trade for larger swaps where slippage may be an issue.
|
|
258
|
+
{% endhint %}
|
|
259
|
+
|
|
260
|
+
***
|
|
261
|
+
|
|
262
|
+
### Chain IDs and corresponding names
|
|
263
|
+
|
|
264
|
+
The `supportedChainIds` field includes a list of chain IDs that each provider supports. The Chain IDs are standard among the crypto space so you may see the chains referenced by them elsewhere too.\
|
|
265
|
+
Below is a table with the chain IDs integrated by SwapKit and their corresponding regular names:
|
|
266
|
+
|
|
267
|
+
| Chain ID | Chain Name |
|
|
268
|
+
| ---------------------- | ------------------------- |
|
|
269
|
+
| `1` | Ethereum Mainnet |
|
|
270
|
+
| `42161` | Arbitrum One |
|
|
271
|
+
| `43114` | Avalanche C-Chain |
|
|
272
|
+
| `8453` | Base |
|
|
273
|
+
| `56` | Binance Smart Chain (BSC) |
|
|
274
|
+
| `137` | Polygon |
|
|
275
|
+
| `10` | Optimism |
|
|
276
|
+
| `100` | Gnosis |
|
|
277
|
+
| `80094` | BeraChain |
|
|
278
|
+
| `728126428` | Tron - TRX |
|
|
279
|
+
| `solana` | Solana |
|
|
280
|
+
| `bitcoin` | Bitcoin |
|
|
281
|
+
| `bitcoincash` | Bitcoin Cash |
|
|
282
|
+
| `litecoin` | Litecoin |
|
|
283
|
+
| `ripple` | XRP - Ripple |
|
|
284
|
+
| `cosmoshub-4` | Cosmos Hub |
|
|
285
|
+
| `near` | Near Chain |
|
|
286
|
+
| `dash` | Dash |
|
|
287
|
+
| `zcash` | ZCash |
|
|
288
|
+
| `dogecoin` | Dogecoin |
|
|
289
|
+
| `kaiyo-1` | Kujira |
|
|
290
|
+
| `mayachain-mainnet-v1` | MayaChain |
|
|
291
|
+
| `radix-mainnet` | Radix |
|
|
292
|
+
| `thorchain-1` | THORChain |
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
# /tokens - Request supported tokens by a swap provider
|
|
297
|
+
|
|
298
|
+
The `/tokens` endpoint provides a list of tokens for a specified provider. This endpoint requires a query parameter to determine which provider's tokens you want to retrieve.
|
|
299
|
+
|
|
300
|
+
**Method:** `GET`\
|
|
301
|
+
**URL:** `https://api.swapkit.dev/tokens`
|
|
302
|
+
|
|
303
|
+
#### Example Request
|
|
304
|
+
|
|
305
|
+
```bash
|
|
306
|
+
curl -X 'GET' \
|
|
307
|
+
'https://api.swapkit.dev/tokens?provider=CHAINFLIP' \
|
|
308
|
+
-H 'accept: application/json' \
|
|
309
|
+
-H "x-api-key: YOUR_VARIABLE_HERE"
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
***
|
|
313
|
+
|
|
314
|
+
### Example shortened response
|
|
315
|
+
|
|
316
|
+
```json
|
|
317
|
+
{
|
|
318
|
+
"provider": "CHAINFLIP",
|
|
319
|
+
"name": "CHAINFLIP",
|
|
320
|
+
"timestamp": "2025-01-11T16:31:04.355Z",
|
|
321
|
+
"version": {
|
|
322
|
+
"major": 1,
|
|
323
|
+
"minor": 0,
|
|
324
|
+
"patch": 0
|
|
325
|
+
},
|
|
326
|
+
"keywords": [],
|
|
327
|
+
"count": 10,
|
|
328
|
+
"tokens": [
|
|
329
|
+
{
|
|
330
|
+
"chain": "BTC",
|
|
331
|
+
"chainId": "bitcoin",
|
|
332
|
+
"ticker": "BTC",
|
|
333
|
+
"identifier": "BTC.BTC",
|
|
334
|
+
"symbol": "BTC",
|
|
335
|
+
"name": "Bitcoin",
|
|
336
|
+
"decimals": 8,
|
|
337
|
+
"logoURI": "https://storage.googleapis.com/token-list-swapkit/images/btc.btc.png",
|
|
338
|
+
"coingeckoId": "bitcoin"
|
|
339
|
+
},
|
|
340
|
+
{
|
|
341
|
+
"chain": "ARB",
|
|
342
|
+
"chainId": "42161",
|
|
343
|
+
"ticker": "ETH",
|
|
344
|
+
"identifier": "ARB.ETH",
|
|
345
|
+
"symbol": "ETH",
|
|
346
|
+
"name": "Arbitrum Ether",
|
|
347
|
+
"decimals": 18,
|
|
348
|
+
"logoURI": "https://storage.googleapis.com/token-list-swapkit/images/arb.eth.png",
|
|
349
|
+
"coingeckoId": "ethereum"
|
|
350
|
+
},
|
|
351
|
+
{
|
|
352
|
+
"chain": "SOL",
|
|
353
|
+
"address": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
|
|
354
|
+
"chainId": "solana",
|
|
355
|
+
"ticker": "USDC",
|
|
356
|
+
"identifier": "SOL.USDC-EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
|
|
357
|
+
"symbol": "USDC-EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
|
|
358
|
+
"name": "Solana USDC",
|
|
359
|
+
"decimals": 6,
|
|
360
|
+
"logoURI": "https://storage.googleapis.com/token-list-swapkit/images/sol.usdc-epjfwdd5aufqssqem2qn1xzybapc8g4weggkzwytdt1v.png"
|
|
361
|
+
},
|
|
362
|
+
...
|
|
363
|
+
]
|
|
364
|
+
}
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
***
|
|
368
|
+
|
|
369
|
+
### Response fields
|
|
370
|
+
|
|
371
|
+
The relevant response fields are:
|
|
372
|
+
|
|
373
|
+
<table><thead><tr><th width="257">Field</th><th width="102">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>provider</code> and <code>name</code></td><td><code>string</code></td><td>The name of the provider specified in the query.</td></tr><tr><td><code>timestamp</code></td><td><code>string</code></td><td>The timestamp of when the response was generated.</td></tr><tr><td><code>count</code></td><td><code>number</code></td><td>The number of tokens included in the response.</td></tr><tr><td><code>tokens</code></td><td><code>array</code></td><td>An array of token objects, each representing a token available for the specified provider.</td></tr></tbody></table>
|
|
374
|
+
|
|
375
|
+
#### For each token, information is provided to properly differentiate it from others:
|
|
376
|
+
|
|
377
|
+
<table><thead><tr><th width="257">Field</th><th width="102">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>chain</code></td><td><code>string</code></td><td>The blockchain the token is associated with (e.g., <code>ETH</code>, <code>BTC</code>, <code>SOL</code>).</td></tr><tr><td><code>address</code></td><td><code>string</code></td><td>The contract address of the token (only provided if it is not the gas token of the network).</td></tr><tr><td><code>chainId</code></td><td><code>string</code></td><td>The ID of the chain. It could be a numeric ID (e.g., <code>42161</code> for Arbitrum) or a name like <code>solana</code>.</td></tr><tr><td><code>ticker</code></td><td><code>string</code></td><td>The ticker symbol of the token (e.g., <code>ETH</code>, <code>BTC</code>).</td></tr><tr><td><code>identifier</code></td><td><code>string</code></td><td>An identifier for the token that combines chain and token address, used to identify the token in SwapKit API.</td></tr><tr><td><code>symbol</code></td><td><code>string</code></td><td>The token symbol, which includes address information.</td></tr><tr><td><code>name</code></td><td><code>string</code></td><td>The full name of the token.</td></tr><tr><td><code>decimals</code></td><td><code>number</code></td><td>The number of decimal places the token supports.</td></tr><tr><td><code>logoURI</code></td><td><code>string</code></td><td>A URL pointing to the token's logo image.</td></tr><tr><td><code>coingeckoId</code></td><td><code>string</code></td><td>The identifier of the token on CoinGecko (if available).</td></tr></tbody></table>
|
|
378
|
+
|
|
379
|
+
***
|
|
380
|
+
|
|
381
|
+
### Notes
|
|
382
|
+
|
|
383
|
+
* The `identifier` is what SwapKit uses to uniquely identify a token in all its requests and responses. It includes the chain, the name and the token address. It is how the token should be named when using the `/quote`endpoint.
|
|
384
|
+
* The identifier is built by putting together Chain.Ticker-ContractAddress (e.g., `"ETH.USDC-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"`).
|
|
385
|
+
* Gas assets like BTC, ETH or SOL don't require a contract address, so their identifier is just `BTC.BTC`for example. 
|
|
386
|
+
* Tokens with an `address` field are specific instances of a token on a given chain (e.g., `USDC` on Ethereum or Solana). While the `coingeckoId`could be shared, we provide the relevant contract address for the token in the specific chain.
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
# /quote - Request a trade quote
|
|
390
|
+
|
|
391
|
+
### Endpoint
|
|
392
|
+
|
|
393
|
+
**Method:** `POST`\
|
|
394
|
+
**URL:** `https://api.swapkit.dev/quote`
|
|
395
|
+
|
|
396
|
+
***
|
|
397
|
+
|
|
398
|
+
### Request parameters
|
|
399
|
+
|
|
400
|
+
```json
|
|
401
|
+
{
|
|
402
|
+
"sellAsset": "string",
|
|
403
|
+
"buyAsset": "string",
|
|
404
|
+
"sellAmount": "string",
|
|
405
|
+
"providers": [
|
|
406
|
+
"string"
|
|
407
|
+
],
|
|
408
|
+
"sourceAddress": "string",
|
|
409
|
+
"destinationAddress": "string",
|
|
410
|
+
"slippage": 100,
|
|
411
|
+
"affiliate": "string",
|
|
412
|
+
"affiliateFee": 1000,
|
|
413
|
+
"allowSmartContractSender": true,
|
|
414
|
+
"allowSmartContractReceiver": true,
|
|
415
|
+
"disableSecurityChecks": true,
|
|
416
|
+
"includeTx": true,
|
|
417
|
+
"cfBoost": true
|
|
418
|
+
}
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
Here's a detailed description of the different parameters:
|
|
422
|
+
|
|
423
|
+
<table data-full-width="false"><thead><tr><th width="230">Parameter</th><th width="110">Type</th><th width="99">Required</th><th>Description</th></tr></thead><tbody><tr><td><code>sellAsset</code></td><td><code>string</code></td><td>✅ Yes</td><td>The asset being sold (e.g. <code>"ETH.ETH"</code>).</td></tr><tr><td><code>buyAsset</code></td><td><code>string</code></td><td>✅ Yes</td><td>The asset being bought (e.g. <code>"BTC.BTC"</code>).</td></tr><tr><td><code>sellAmount</code></td><td><code>string</code></td><td>✅ Yes</td><td>Amount in basic units (decimals separated with a dot).</td></tr><tr><td><code>providers</code></td><td><code>array</code></td><td>❌ No</td><td>Limits the possible liquidity providers.</td></tr><tr><td><code>sourceAddress</code></td><td><code>string</code></td><td>✅ Yes</td><td>Address of the sender.</td></tr><tr><td><code>destinationAddress</code></td><td><code>string</code></td><td>✅ Yes</td><td>Address of the recipient.</td></tr><tr><td><code>slippage</code></td><td><code>number</code></td><td>❌ No</td><td>Max slippage in percentage (5 = 5%).</td></tr><tr><td><code>affiliate</code></td><td><code>string</code></td><td>❌ No</td><td>Affiliate address for revenue sharing.</td></tr><tr><td><code>affiliateFee</code></td><td><code>number</code></td><td>❌ No</td><td>Fee percentage in basis points (50= 0.5%).</td></tr><tr><td><code>allowSmartContractSender</code></td><td><code>boolean</code></td><td>❌ No</td><td>Allow smart contract as sender.</td></tr><tr><td><code>allowSmartContractReceiver</code></td><td><code>boolean</code></td><td>❌ No</td><td>Allow smart contract as receiver.</td></tr><tr><td><code>disableSecurityChecks</code></td><td><code>boolean</code></td><td>❌ No</td><td>Bypass security checks.</td></tr><tr><td><code>includeTx</code></td><td><code>boolean</code></td><td>❌ No</td><td>Include transaction details in the response. Read more about it <a href="quote-implementation-flow">here</a>.</td></tr><tr><td><code>cfBoost</code></td><td><code>boolean</code></td><td>❌ No</td><td>Enables Chainflip boost for better rates.</td></tr></tbody></table>
|
|
424
|
+
|
|
425
|
+
**Note:** Asset names for `sellAsset` and `buyAsset` should follow the following nomenclature:
|
|
426
|
+
|
|
427
|
+
* Chain.Asset (e.g., `"BTC.BTC"` or `"ARB.ETH"`)
|
|
428
|
+
* Chain.Asset-ContractAddress (e.g., `"ETH.USDC-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"`)
|
|
429
|
+
|
|
430
|
+
This is the `identifier`as provided in the [`/tokens`](https://docs.swapkit.dev/swapkit-api/tokens-request-supported-tokens-by-a-swap-provider) endpoint.
|
|
431
|
+
|
|
432
|
+
{% hint style="warning" %}
|
|
433
|
+
When you test your integration, use an address with enough `sellAsset` balance to cover the trade. This will ensure you receive complete responses.
|
|
434
|
+
{% endhint %}
|
|
435
|
+
|
|
436
|
+
***
|
|
437
|
+
|
|
438
|
+
### Example request
|
|
439
|
+
|
|
440
|
+
A simple request to trade `ETH.ETH`to `BTC.BTC`may omit the `providers`list if you can manage them in the response, but should include the amount, the involved addresses and slippage settings.
|
|
441
|
+
|
|
442
|
+
The expiration time returned by the endpoint is an estimation. We recommend requesting a new quote at least every minute if the trade has not been executed yet.
|
|
443
|
+
|
|
444
|
+
{% hint style="info" %}
|
|
445
|
+
Using the header `x-api-key`in your `/quote`request automatically applies your affiliate addresses and fee values set up through our [partners dashboard](https://docs.swapkit.dev/monetization#step-3-set-affiliate-fee-tiers) in the response parameters.
|
|
446
|
+
{% endhint %}
|
|
447
|
+
|
|
448
|
+
{% tabs %}
|
|
449
|
+
{% tab title="cURL" %}
|
|
450
|
+
|
|
451
|
+
```sh
|
|
452
|
+
curl -X POST "https://api.swapkit.dev/quote" \
|
|
453
|
+
-H "Content-Type: application/json" \
|
|
454
|
+
-H "x-api-key: YOUR_VARIABLE_HERE" \
|
|
455
|
+
-d '{
|
|
456
|
+
"sellAsset": "ETH.ETH",
|
|
457
|
+
"buyAsset": "BTC.BTC",
|
|
458
|
+
"sellAmount": "0.1",
|
|
459
|
+
"sourceAddress": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
|
|
460
|
+
"destinationAddress": "357a3So9CbsNfBBgFYACGvxxS6tMaDoa1P",
|
|
461
|
+
"slippage": 10,
|
|
462
|
+
"includeTx": true
|
|
463
|
+
}'
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
{% endtab %}
|
|
467
|
+
{% endtabs %}
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
# /quote - Implementation flow
|
|
471
|
+
|
|
472
|
+
An important part of our service is the possibility of including transaction data in a `/quote` response.\
|
|
473
|
+
This option is activated when the "`includeTx": true` request parameter is used, but it is important to keep a proper quote request flow for a better performing integration.
|
|
474
|
+
|
|
475
|
+
### 1. Initial Quote Request
|
|
476
|
+
|
|
477
|
+
First, fetch quotes with "`includeTx": false` (or unset, as false is the default). For this step, you may leave out `"sourceAddress"` and `"destinationAddress"` since they are not needed to process a quote:
|
|
478
|
+
|
|
479
|
+
```bash
|
|
480
|
+
curl -X POST "https://api.swapkit.dev/quote" \
|
|
481
|
+
-H "Content-Type: application/json" \
|
|
482
|
+
-H "x-api-key: YOUR_VARIABLE_HERE" \
|
|
483
|
+
-d '{
|
|
484
|
+
"sellAsset": "BTC.BTC",
|
|
485
|
+
"buyAsset": "ETH.ETH",
|
|
486
|
+
"sellAmount": "0.1",
|
|
487
|
+
"slippage": 3,
|
|
488
|
+
"includeTx": false
|
|
489
|
+
}'
|
|
490
|
+
```
|
|
491
|
+
|
|
492
|
+
You can filter for the providers you have integrated using the `"providers"` argument if you want to limit the options shown.
|
|
493
|
+
|
|
494
|
+
This returns a regular quote response including pricing information, estimated timing and fees, and route details with the available providers, but without transaction data.
|
|
495
|
+
|
|
496
|
+
### 2. Identify the Provider route you want to use
|
|
497
|
+
|
|
498
|
+
After offering a price to the user of your application, the user would then accept it. This identifies what provider offers the best match for the route you quoted for.
|
|
499
|
+
|
|
500
|
+
Before the user gets offered a transaction to sign though, you will request a new quote filtering with this specific provider and requesting a transaction object.
|
|
501
|
+
|
|
502
|
+
### 3. Transaction Building
|
|
503
|
+
|
|
504
|
+
When the user is ready to execute the swap, request a new quote with "`includeTx": true` and filtering by provider:
|
|
505
|
+
|
|
506
|
+
```bash
|
|
507
|
+
curl -X POST "https://api.swapkit.dev/quote" \
|
|
508
|
+
-H "Content-Type: application/json" \
|
|
509
|
+
-H "x-api-key: YOUR_VARIABLE_HERE" \
|
|
510
|
+
-d '{
|
|
511
|
+
"sellAsset": "BTC.BTC",
|
|
512
|
+
"buyAsset": "ETH.ETH",
|
|
513
|
+
"sellAmount": "0.1",
|
|
514
|
+
"sourceAddress": "357a3So9CbsNfBBgFYACGvxxS6tMaDoa1P",
|
|
515
|
+
"destinationAddress": "0x0a4c79cE84202b03e95B7a692E5D728d83C44c76",
|
|
516
|
+
"providers": ["NEAR"],
|
|
517
|
+
"slippage": 3,
|
|
518
|
+
"includeTx": true
|
|
519
|
+
}'
|
|
520
|
+
```
|
|
521
|
+
|
|
522
|
+
Setting `includeTx: true` results in slightly slower response times as the system performs additional validations and transaction building. This is why it is also best to now filter the providers used, so only the specific best quote is returned.
|
|
523
|
+
|
|
524
|
+
The quote response will now include additional transaction related fields, different for each provider. You can show the price to the user again for signing or compare internally to the previous value before offering it:
|
|
525
|
+
|
|
526
|
+
```json
|
|
527
|
+
{
|
|
528
|
+
// ... all fields from above, plus:
|
|
529
|
+
"targetAddress": "1FSHYruFaYjm5FQrzB3LmF15FMC3QwUFmy",
|
|
530
|
+
"inboundAddress": "1FSHYruFaYjm5FQrzB3LmF15FMC3QwUFmy",
|
|
531
|
+
"tx": "cHNidP8BAHUCAAAAAc86GvpcKcJoCV1YpX9orAcE/ZckHbLzuTXOPl0McccZAAAAAAD/////AoCWmAAAAAAAGXapFJ5Z+YVfu2g/WM/XGmu9FBGSeS5wiKx/LhEm4wAAABepFFKL8plEPOVGF9/52YVT+SKl3opehwAAAAAAAQEg/8SpJuMAAAAXqRRSi/KZRDzlRhff+dmFU/kipd6KXocAAAA=",
|
|
532
|
+
"meta": {
|
|
533
|
+
// ... existing meta fields, plus:
|
|
534
|
+
"txType": "PSBT"
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
```
|
|
538
|
+
|
|
539
|
+
***
|
|
540
|
+
|
|
541
|
+
### Transaction Building Process
|
|
542
|
+
|
|
543
|
+
When `includeTx: true` is set, the system performs the following validations:
|
|
544
|
+
|
|
545
|
+
#### 1. Balance Verification
|
|
546
|
+
|
|
547
|
+
The system first checks if the source address has sufficient balance to cover the `sellAmount`. If insufficient funds are detected, an `insufficientBalance` error is thrown for the entire request.
|
|
548
|
+
|
|
549
|
+
#### 2. Transaction Building
|
|
550
|
+
|
|
551
|
+
If the balance check passes, the system attempts to build the transaction. In certain edge cases, the wallet may have enough balance to match the `sellAmount` but insufficient funds to cover network fees. Since different providers have varying transaction sizes, some may return valid transaction data while others might fail with an `unableToBuildTransaction` error.
|
|
552
|
+
|
|
553
|
+
#### 3. Successful Response
|
|
554
|
+
|
|
555
|
+
If all validations pass, you'll receive a complete route with transaction data that can be directly signed and broadcast.
|
|
556
|
+
|
|
557
|
+
### Key Fields
|
|
558
|
+
|
|
559
|
+
* `targetAddress` The deposit address where funds should be sent, or the address of the contract that should be called.
|
|
560
|
+
* `inboundAddress` The address monitoring for incoming transactions.
|
|
561
|
+
* `tx` The transaction data ready for signing.
|
|
562
|
+
* `txType` The format of the transaction data (e.g., "PSBT" for Bitcoin or "EVM" for EVM chains).
|
|
563
|
+
|
|
564
|
+
### Error Handling
|
|
565
|
+
|
|
566
|
+
Be prepared to handle the following errors when using `includeTx: true`:
|
|
567
|
+
|
|
568
|
+
* `insufficientBalance` The source address doesn't have enough tokens for the swap.
|
|
569
|
+
* `insufficientAllowance`: The source address doesn't have enough tokens approved for the contract interaction. Relevant for tokens in EVM networks.
|
|
570
|
+
* `unableToBuildTransaction` The wallet has sufficient tokens but insufficient funds for network fees.
|
|
571
|
+
|
|
572
|
+
This is an example error for a wallet without enough balance:
|
|
573
|
+
|
|
574
|
+
```json
|
|
575
|
+
{
|
|
576
|
+
"message": "Cannot build transaction. Insufficient balance for asset ETH.USDC-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 amount 700 address 0x...",
|
|
577
|
+
"error": "insufficientBalance",
|
|
578
|
+
"data": {
|
|
579
|
+
"chain": "ETH.USDC-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
580
|
+
"amount": "700",
|
|
581
|
+
"address": "0x..."
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
```
|
|
585
|
+
|
|
586
|
+
|
|
587
|
+
# /quote - Understanding the response
|
|
588
|
+
|
|
589
|
+
### Response structure
|
|
590
|
+
|
|
591
|
+
The response lists the available providers for the route, limited by the list used to quote it. If the parameter was not included the response lists all possible providers.\
|
|
592
|
+
Estimated output, expected slippage and estimated time are some of the information listed for each swap provider so you can choose the best routes. Additionally, SwapKit provides tags to aid you in the process and identify what we would consider ourselves.
|
|
593
|
+
|
|
594
|
+
{% hint style="warning" %}
|
|
595
|
+
When you test your integration, use an address with enough `sellAsset` balance to cover the trade. This will ensure you receive complete responses.
|
|
596
|
+
{% endhint %}
|
|
597
|
+
|
|
598
|
+
#### **`quoteId`**
|
|
599
|
+
|
|
600
|
+
A unique identifier for the quote request. You can optionally store it to reference the quote provided by SwapKit at a later date.
|
|
601
|
+
|
|
602
|
+
***
|
|
603
|
+
|
|
604
|
+
### `routes` Object
|
|
605
|
+
|
|
606
|
+
The `routes` array contains possible swap options, each identified by the `providers`object at the start.
|
|
607
|
+
|
|
608
|
+
<table><thead><tr><th width="304">Field</th><th width="107">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>providers</code></td><td><code>array</code></td><td>List of providers available for this route (<code>CHAINFLIP</code>, <code>THORHCAIN</code>etc.).</td></tr><tr><td><code>sellAsset</code></td><td><code>string</code></td><td>The asset being sold (e.g., <code>"ETH.ETH"</code>).</td></tr><tr><td><code>buyAsset</code></td><td><code>string</code></td><td>The asset being bought (e.g., <code>"BTC.BTC"</code>).</td></tr><tr><td><code>sellAmount</code></td><td><code>string</code></td><td>Amount of the sell asset in smallest units.</td></tr><tr><td><code>expectedBuyAmount</code></td><td><code>string</code></td><td>Estimated amount of the buy asset to be received.</td></tr><tr><td><code>expectedBuyAmountMaxSlippage</code></td><td><code>string</code></td><td>Worst-case buy amount considering max slippage.</td></tr><tr><td><code>sourceAddress</code></td><td><code>string</code></td><td>Source address.</td></tr><tr><td><code>destinationAddress</code></td><td><code>string</code></td><td>Destination address.</td></tr><tr><td><code>targetAdddress</code></td><td><code>string</code></td><td>Address to send the initial transaction to.</td></tr><tr><td><code>approvalAddress</code></td><td><code>string</code></td><td>Address to approve spending to (when swapping tokens on EVM)</td></tr><tr><td><code>memo</code></td><td><code>string</code></td><td>Transaction memo, which can be used in UTXO chains directly.</td></tr><tr><td><code>fees</code></td><td><code>array</code></td><td>List of fees applied to the swap (inbound, network, affiliate).</td></tr><tr><td><code>tx</code></td><td><code>array</code></td><td>Transaction object for EVM chains, a <a href="https://en.bitcoin.it/wiki/BIP_0174">PSBT</a> object for BTC etc.</td></tr><tr><td><code>estimatedTime</code></td><td><code>object</code></td><td>Estimated time for different phases of the swap.</td></tr><tr><td><code>totalSlippageBps</code></td><td><code>number</code></td><td>Expected total slippage.</td></tr><tr><td><code>legs</code></td><td><code>array</code></td><td>The different involved steps in the swap.</td></tr><tr><td><code>warnings</code></td><td><code>array</code></td><td>Potential warnings about this swap provider.</td></tr><tr><td><code>meta</code></td><td><code>array</code></td><td>Other information about the transaction.</td></tr><tr><td><code>priceImpact</code></td><td><code>number</code></td><td>Price impact percentage in USD terms.</td></tr></tbody></table>
|
|
609
|
+
|
|
610
|
+
* The `tx`object is only provided if the `"includeTx":true`parameter was included. It can be used as the transaction data for EVM chains. It won't be provided if the token to swap is not approved for the `approvalAddress` . It is explained in more detail [here](https://docs.swapkit.dev/swapkit-api/quote-implementation-flow).
|
|
611
|
+
* `targetAddress` is the address to send the transaction to, but Chainflip transactions need to use a [deposit channel](https://docs.swapkit.dev/swapkit-api/chainflip-broker-channel-opening-a-chainflip-deposit-channel) instead and don't require approval. 
|
|
612
|
+
|
|
613
|
+
{% hint style="info" %}
|
|
614
|
+
It is necessary to approve `approvalAddress` as an spender if you are swapping tokens on an EVM chain.
|
|
615
|
+
{% endhint %}
|
|
616
|
+
|
|
617
|
+
In many cases `targetAddress` and `approvalAddress` will be the same but they will differ when using dex aggregation for a cross chain swap (swapping an ERC20 into BTC.BTC for example).
|
|
618
|
+
|
|
619
|
+
#### **Example `routes` Object:**
|
|
620
|
+
|
|
621
|
+
```json
|
|
622
|
+
{
|
|
623
|
+
"providers": ["MAYACHAIN"],
|
|
624
|
+
"sellAsset": "ETH.ETH",
|
|
625
|
+
"sellAmount": "0.1",
|
|
626
|
+
"buyAsset": "BTC.BTC",
|
|
627
|
+
"expectedBuyAmount": "0.00275103",
|
|
628
|
+
"expectedBuyAmountMaxSlippage": "0.00247592",
|
|
629
|
+
"sourceAddress": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
|
|
630
|
+
"destinationAddress": "357a3So9CbsNfBBgFYACGvxxS6tMaDoa1P",
|
|
631
|
+
"targetAddress": "0xe3985E6b61b814F7Cdb188766562ba71b446B46d",
|
|
632
|
+
"inboundAddress": "0x62b54578b77d0ccfe74b4a009d9ecbc82777c9ff",
|
|
633
|
+
"expiration": "1738931194",
|
|
634
|
+
"memo": "=:b:357a3So9CbsNfBBgFYACGvxxS6tMaDoa1P:247592:_/sk:20/100",
|
|
635
|
+
"fees": [{
|
|
636
|
+
...
|
|
637
|
+
}],
|
|
638
|
+
"tx": {
|
|
639
|
+
"to": "0xe3985E6b61b814F7Cdb188766562ba71b446B46d",
|
|
640
|
+
"from": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
|
|
641
|
+
"gas": "0x9714",
|
|
642
|
+
"gasPrice": "0x5be199fd",
|
|
643
|
+
"value": "100000000000000000",
|
|
644
|
+
"data": "0x44bc937b00000000000000000000000062b54578b77d0ccfe74b4a009d9ecbc82777c9ff0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000016345785d8a000000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000067a5fbfa00000000000000000000000000000000000000000000000000000000000000393d3a623a3335376133536f394362734e6642426746594143477678785336744d61446f6131503a3234373539323a5f2f736b3a32302f31303000000000000000"
|
|
645
|
+
},
|
|
646
|
+
"estimatedTime": {
|
|
647
|
+
...
|
|
648
|
+
},
|
|
649
|
+
"totalSlippageBps": 246,
|
|
650
|
+
"legs": [{
|
|
651
|
+
...
|
|
652
|
+
}],
|
|
653
|
+
"warnings": [],
|
|
654
|
+
"meta": {
|
|
655
|
+
...
|
|
656
|
+
}
|
|
657
|
+
"priceImpact": -0.38,
|
|
658
|
+
"approvalAddress": "0xe3985E6b61b814F7Cdb188766562ba71b446B46d",
|
|
659
|
+
}
|
|
660
|
+
```
|
|
661
|
+
|
|
662
|
+
***
|
|
663
|
+
|
|
664
|
+
### Fees breakdown
|
|
665
|
+
|
|
666
|
+
Fees are categorized into different types based on their role in the swap process.
|
|
667
|
+
|
|
668
|
+
<table><thead><tr><th width="297">Fee Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>Inbound</strong></td><td>Fee for transferring the sell asset, paid from the user's wallet.</td></tr><tr><td><strong>Network</strong></td><td>Blockchain transaction fee for processing the swap.</td></tr><tr><td><strong>Affiliate</strong></td><td>Fee paid to the specified affiliate.</td></tr><tr><td><strong>Service</strong></td><td>SwapKit's service fee.</td></tr><tr><td><strong>Outbound</strong></td><td>Fee for transferring the buy asset to the destination address.</td></tr><tr><td><strong>Liquidity</strong></td><td>Fee applied by the liquidity provider to facilitate the swap.</td></tr></tbody></table>
|
|
669
|
+
|
|
670
|
+
Only the inbound fee will be paid from the source wallet. The other fees are deducted from the output, and the output values provided by the endpoint already take this into consideration.
|
|
671
|
+
|
|
672
|
+
***
|
|
673
|
+
|
|
674
|
+
### Transaction details
|
|
675
|
+
|
|
676
|
+
Transaction details are only included if the option `"includeTx": true` was used in the `/quote`request. It provides an object valid to initiate a transaction in the source chain. These objects can be used so sing and send the transaction using the main libraries for each blockchain.
|
|
677
|
+
|
|
678
|
+
***
|
|
679
|
+
|
|
680
|
+
### Estimated time
|
|
681
|
+
|
|
682
|
+
The estimated time in seconds for the swap is divided into the following phases:
|
|
683
|
+
|
|
684
|
+
* **Inbound:** Time taken to receive the sell asset.
|
|
685
|
+
* **Swap:** Time taken for the swap process.
|
|
686
|
+
* **Outbound:** Time taken to transfer the bought asset to the destination. This includes the provider outbound time, not only the transaction time.
|
|
687
|
+
* **Total:** The sum of all time estimates.
|
|
688
|
+
|
|
689
|
+
#### **Example estimated time:**
|
|
690
|
+
|
|
691
|
+
```json
|
|
692
|
+
"estimatedTime": {
|
|
693
|
+
"inbound": 30,
|
|
694
|
+
"swap": 6,
|
|
695
|
+
"outbound": 624,
|
|
696
|
+
"total": 660
|
|
697
|
+
}
|
|
698
|
+
```
|
|
699
|
+
|
|
700
|
+
***
|
|
701
|
+
|
|
702
|
+
### Transaction metadata
|
|
703
|
+
|
|
704
|
+
The `meta` section provides additional information about the swap.
|
|
705
|
+
|
|
706
|
+
| **priceImpact** | The expected impact on market rates. |
|
|
707
|
+
| ---------------------------- | ---------------------------------------------------------------------------- |
|
|
708
|
+
| **affiliate - affiliateFee** | Details of affiliate commissions. |
|
|
709
|
+
| **tags** | \["FASTEST", "RECOMMENDED", "CHEAPEST"] |
|
|
710
|
+
| **approvalAddress** | The contract address for ERC-20 approvals. |
|
|
711
|
+
| **chainflip** | Information necessary to open a deposit channel for the Chainflip providers. |
|
|
712
|
+
|
|
713
|
+
#### **Example `meta` Object:**
|
|
714
|
+
|
|
715
|
+
```json
|
|
716
|
+
"meta": {
|
|
717
|
+
"priceImpact": -1.69,
|
|
718
|
+
"assets": [{
|
|
719
|
+
"asset": "ETH.ETH",
|
|
720
|
+
"price": 2752.14,
|
|
721
|
+
"image": "https://storage.googleapis.com/token-list-swapkit/images/eth.eth.png"
|
|
722
|
+
}, {
|
|
723
|
+
"asset": "BTC.BTC",
|
|
724
|
+
"price": 97648,
|
|
725
|
+
"image": "https://storage.googleapis.com/token-list-swapkit/images/btc.btc.png"
|
|
726
|
+
}],
|
|
727
|
+
"approvalAddress": "0xD37BbE5744D730a1d98d8DC97c42F0Ca46aD7146",
|
|
728
|
+
"tags": ["FASTEST"],
|
|
729
|
+
"affiliate": "sk",
|
|
730
|
+
"affiliateFee": "100",
|
|
731
|
+
"txType": "EVM"
|
|
732
|
+
}
|
|
733
|
+
```
|
|
734
|
+
|
|
735
|
+
The `"tags"`can help recognize what SwapKit considers the best routes by filtering through the `["FASTEST", "RECOMMENDED", "CHEAPEST"]` identification.<br>
|
|
736
|
+
|
|
737
|
+
<table><thead><tr><th width="283">Tag</th><th>Description</th></tr></thead><tbody><tr><td><strong>RECOMMENDED</strong></td><td>Best overall route based on output and speed.</td></tr><tr><td><strong>CHEAPEST</strong></td><td>The route with the maximum output.</td></tr><tr><td><strong>FASTEST</strong></td><td>The route with the shortest total estimated time.</td></tr></tbody></table>
|
|
738
|
+
|
|
739
|
+
Additionally the `"chainflip"`object is added for `CHAINFLIP` and `CHAINFLIP_STREAMING`swaps. This is used to [open a deposit channel](https://docs.swapkit.dev/swapkit-api/chainflip-broker-channel-opening-a-chainflip-deposit-channel), a necessary step to initiate a trade.
|
|
740
|
+
|
|
741
|
+
```json
|
|
742
|
+
"chainflip": {
|
|
743
|
+
"sellAsset": {
|
|
744
|
+
"chain": "Ethereum",
|
|
745
|
+
"asset": "ETH"
|
|
746
|
+
},
|
|
747
|
+
"buyAsset": {
|
|
748
|
+
"chain": "Bitcoin",
|
|
749
|
+
"asset": "BTC"
|
|
750
|
+
},
|
|
751
|
+
"destinationAddress": "357a3So9CbsNfBBgFYACGvxxS6tMaDoa1P",
|
|
752
|
+
"affiliateFees": [{
|
|
753
|
+
"brokerAddress": "cFNwtr2mPhpUEB5AyJq38DqMKMkSdzaL9548hajN2DRTwh7Mq",
|
|
754
|
+
"feeBps": 100
|
|
755
|
+
}],
|
|
756
|
+
"refundParameters": {
|
|
757
|
+
"minPrice": "0x2c166186363d48000000000",
|
|
758
|
+
"refundAddress": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
|
|
759
|
+
"retryDuration": 150
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
```
|
|
763
|
+
|
|
764
|
+
***
|
|
765
|
+
|
|
766
|
+
### Warnings
|
|
767
|
+
|
|
768
|
+
Warnings highlight potential issues such as high price impact or insufficient liquidity.
|
|
769
|
+
|
|
770
|
+
#### **Example warning:**
|
|
771
|
+
|
|
772
|
+
```json
|
|
773
|
+
"warnings": [
|
|
774
|
+
{
|
|
775
|
+
"code": "highPriceImpact",
|
|
776
|
+
"display": "-10%",
|
|
777
|
+
"tooltip": "This swap has a high value impact given the current liquidity and network fees. There may be a large difference between the amount of your input token and what you will receive in the output token."
|
|
778
|
+
}
|
|
779
|
+
]
|
|
780
|
+
```
|
|
781
|
+
|
|
782
|
+
***
|
|
783
|
+
|
|
784
|
+
### Provider errors
|
|
785
|
+
|
|
786
|
+
If certain providers cannot facilitate the swap, the response may include error messages under `providerErrors`.
|
|
787
|
+
|
|
788
|
+
#### **Example provider error:**
|
|
789
|
+
|
|
790
|
+
```json
|
|
791
|
+
"providerErrors": [{
|
|
792
|
+
"provider": "CHAINFLIP_STREAMING",
|
|
793
|
+
"errorCode": "swapAmountTooSmall"
|
|
794
|
+
}]
|
|
795
|
+
```
|
|
796
|
+
|
|
797
|
+
# /chainflip/broker/channel - Opening a Chainflip deposit channel
|
|
798
|
+
|
|
799
|
+
To initiate a swap through the `CHAINFLIP`or `CHAINFLIP_STREAMING`providers, a deposit channel must be opened first.
|
|
800
|
+
|
|
801
|
+
**Method:** `POST`\
|
|
802
|
+
**URL:** `https://api.swapkit.dev/chainflip/broker/channel`
|
|
803
|
+
|
|
804
|
+
The information needed to open a channel is included inside the `meta.chainflip`object of the `/quote`response, as in the example below. The object needs to be passed to the `/chainflip/broker/channel`endpoint, which creates a deposit channel.\
|
|
805
|
+
It contains a deposit address for the chain initiating the swap, where the tokens can be sent to.
|
|
806
|
+
|
|
807
|
+
```json
|
|
808
|
+
"meta": {
|
|
809
|
+
...
|
|
810
|
+
"chainflip": {
|
|
811
|
+
"sellAsset": {
|
|
812
|
+
"chain": "Ethereum",
|
|
813
|
+
"asset": "ETH"
|
|
814
|
+
},
|
|
815
|
+
"buyAsset": {
|
|
816
|
+
"chain": "Bitcoin",
|
|
817
|
+
"asset": "BTC"
|
|
818
|
+
},
|
|
819
|
+
"destinationAddress": "357a3So9CbsNfBBgFYACGvxxS6tMaDoa1P",
|
|
820
|
+
"affiliateFees": [{
|
|
821
|
+
"brokerAddress": "cFNwtr2mPhpUEB5AyJq38DqMKMkSdzaL9548hajN2DRTwh7Mq",
|
|
822
|
+
"feeBps": 100
|
|
823
|
+
}],
|
|
824
|
+
"refundParameters": {
|
|
825
|
+
"minPrice": "0x2c166186363d48000000000",
|
|
826
|
+
"refundAddress": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
|
|
827
|
+
"retryDuration": 150
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
```
|
|
832
|
+
|
|
833
|
+
As an example a channel can be requested as:
|
|
834
|
+
|
|
835
|
+
{% tabs %}
|
|
836
|
+
{% tab title="cURL" %}
|
|
837
|
+
|
|
838
|
+
<pre class="language-sh"><code class="lang-sh"><strong>curl -X 'POST' \
|
|
839
|
+
</strong> 'https://api.swapkit.dev/chainflip/broker/channel' \
|
|
840
|
+
-H 'Content-Type: application/json' \
|
|
841
|
+
-H "x-api-key: YOUR_VARIABLE_HERE" \
|
|
842
|
+
-d '{
|
|
843
|
+
"sellAsset": {
|
|
844
|
+
"chain": "Ethereum",
|
|
845
|
+
"asset": "ETH"
|
|
846
|
+
},
|
|
847
|
+
"buyAsset": {
|
|
848
|
+
"chain": "Bitcoin",
|
|
849
|
+
"asset": "BTC"
|
|
850
|
+
},
|
|
851
|
+
"destinationAddress": "357a3So9CbsNfBBgFYACGvxxS6tMaDoa1P",
|
|
852
|
+
"affiliateFees": [{
|
|
853
|
+
"brokerAddress": "cFNwtr2mPhpUEB5AyJq38DqMKMkSdzaL9548hajN2DRTwh7Mq",
|
|
854
|
+
"feeBps": 100
|
|
855
|
+
}],
|
|
856
|
+
"refundParameters": {
|
|
857
|
+
"minPrice": "0x2c166186363d48000000000",
|
|
858
|
+
"refundAddress": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
|
|
859
|
+
"retryDuration": 150
|
|
860
|
+
}
|
|
861
|
+
}'
|
|
862
|
+
</code></pre>
|
|
863
|
+
|
|
864
|
+
{% endtab %}
|
|
865
|
+
{% endtabs %}
|
|
866
|
+
|
|
867
|
+
The response contains a `depositAddress`which funds can be sent to.\
|
|
868
|
+
No approval is needed for this address in the case of ERC-20 tokens, and a memo is not needed either.
|
|
869
|
+
|
|
870
|
+
```json
|
|
871
|
+
{
|
|
872
|
+
"depositAddress": "0xd3f189d1cab37e5dc1f920639ed13bf61132ab16",
|
|
873
|
+
"channelId": "6543210-Ethereum-1933",
|
|
874
|
+
"explorerUrl": "https://scan.chainflip.io/channels/6543210-Ethereum-1984"
|
|
875
|
+
}
|
|
876
|
+
```
|
|
877
|
+
|
|
878
|
+
***
|
|
879
|
+
|
|
880
|
+
Here is an example integrating a `/quote`request with opening a channel:
|
|
881
|
+
|
|
882
|
+
```javascript
|
|
883
|
+
async function swapThroughChainflip () {
|
|
884
|
+
const request = {
|
|
885
|
+
sellAsset: "SOL.SOL",
|
|
886
|
+
buyAsset: "BTC.BTC",
|
|
887
|
+
sellAmount: "1",
|
|
888
|
+
providers: ["CHAINFLIP", "CHAINFLIP_STREAMING"],
|
|
889
|
+
sourceAddress: "sol_address",
|
|
890
|
+
destinationAddress: "btc_address",
|
|
891
|
+
slippage: 1.5,
|
|
892
|
+
};
|
|
893
|
+
|
|
894
|
+
const quoteResponse = await fetch('https://api.swapkit.dev/quote', {
|
|
895
|
+
method: 'POST',
|
|
896
|
+
headers: {
|
|
897
|
+
'Content-Type': 'application/json',
|
|
898
|
+
'x-api-key': apiKey,
|
|
899
|
+
},
|
|
900
|
+
body: JSON.stringify(request),
|
|
901
|
+
});
|
|
902
|
+
|
|
903
|
+
const [chainflipRoute, chainflipStreamingRoute] = await quoteResponse.json();
|
|
904
|
+
|
|
905
|
+
// Pick deposit channel info from quote response
|
|
906
|
+
|
|
907
|
+
const chainflipDepositChannelParams = chainflipRoute.meta.chainflip;
|
|
908
|
+
|
|
909
|
+
// Use params to open deposit channel
|
|
910
|
+
|
|
911
|
+
const depositChannelResponse = await fetch('https://api.swapkit.dev/chainflip/broker/channel', {
|
|
912
|
+
method: 'POST',
|
|
913
|
+
headers: {
|
|
914
|
+
'Content-Type': 'application/json',
|
|
915
|
+
'x-api-key': apiKey,
|
|
916
|
+
},
|
|
917
|
+
body: JSON.stringify(chainflipDepositChannelParams),
|
|
918
|
+
});
|
|
919
|
+
|
|
920
|
+
const depositChannel = await depositChannelResponse.json();
|
|
921
|
+
|
|
922
|
+
|
|
923
|
+
const { depositAddress, explorerUrl } = depositChannel;
|
|
924
|
+
// Send funds to deposit address
|
|
925
|
+
...
|
|
926
|
+
|
|
927
|
+
}
|
|
928
|
+
```
|
|
929
|
+
|
|
930
|
+
|
|
931
|
+
# /track - Request the status of a swap
|
|
932
|
+
|
|
933
|
+
The `/track` endpoint provides real-time status information for a specific transaction. It is particularly useful for tracking the progress and details of swaps, transfers, and other operations. To use this endpoint, you normally provide the **chain ID** and **transaction hash**.\
|
|
934
|
+
For NEAR Intents swaps, you can also call the endpoint with **depositAddress**, which is the address the deposit transaction was sent to.\
|
|
935
|
+
\
|
|
936
|
+
For a complete list of chain IDs used by SwapKit you can [check the table here](https://docs.swapkit.dev/providers-request-supported-chains-by-a-swap-provider#chain-ids-and-corresponding-names).
|
|
937
|
+
|
|
938
|
+
**Method:** `POST`\
|
|
939
|
+
**URL:** `https://api.swapkit.dev/track` 
|
|
940
|
+
|
|
941
|
+
SwapKit has it's own transaction tracking interface here: <https://track.swapkit.dev/>. You can also directly fill the fields by directing users to `https://track.swapkit.dev/?hash={{hash}}` by populating it with the respective transaction hash.
|
|
942
|
+
|
|
943
|
+
#### Request Body:
|
|
944
|
+
|
|
945
|
+
<table><thead><tr><th>Field</th><th width="172">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>hash</code></td><td><code>string</code></td><td>Transaction hash (required if using <code>chainId</code>)</td></tr><tr><td><code>chainId</code></td><td><code>string</code></td><td>Chain ID of the transaction (required if using <code>hash</code>)</td></tr><tr><td><code>depositAddress</code></td><td><code>string</code></td><td>Deposit address used to swap with NEAR Intents, can be used instead of <code>hash</code> and <code>chainId</code></td></tr></tbody></table>
|
|
946
|
+
|
|
947
|
+
NEAR Intents swaps can still be tracked normally indicating the transaction hash of the deposit and the respective chain id. Using `depositAddress` is an additional option but observing executed hashes is easier if users are connected to your application.
|
|
948
|
+
|
|
949
|
+
#### Example Requests:
|
|
950
|
+
|
|
951
|
+
<details>
|
|
952
|
+
|
|
953
|
+
<summary><strong><code>hash</code> and <code>chainId</code></strong></summary>
|
|
954
|
+
|
|
955
|
+
```bash
|
|
956
|
+
curl -X 'POST' \
|
|
957
|
+
'https://api.swapkit.dev/track' \
|
|
958
|
+
-H 'Content-Type: application/json' \
|
|
959
|
+
-H "x-api-key: YOUR_API_KEY_HERE" \
|
|
960
|
+
-d '{
|
|
961
|
+
"hash": "0x1890aba1c0b25126892af2ab09f5c1bba75adefc47918a96ea498764ab643ce9",
|
|
962
|
+
"chainId": "1"
|
|
963
|
+
}'
|
|
964
|
+
```
|
|
965
|
+
|
|
966
|
+
</details>
|
|
967
|
+
|
|
968
|
+
<details>
|
|
969
|
+
|
|
970
|
+
<summary><strong><code>depositAddress</code></strong></summary>
|
|
971
|
+
|
|
972
|
+
```bash
|
|
973
|
+
curl -X 'POST' \
|
|
974
|
+
'https://api.swapkit.dev/track' \
|
|
975
|
+
-H 'Content-Type: application/json' \
|
|
976
|
+
-H "x-api-key: YOUR_VARIABLE_HERE" \
|
|
977
|
+
-d '{
|
|
978
|
+
"depositAddress": "0x6f2B69c522031A7640b432172Ac84e57Dc0a3A63"
|
|
979
|
+
}'
|
|
980
|
+
```
|
|
981
|
+
|
|
982
|
+
</details>
|
|
983
|
+
|
|
984
|
+
***
|
|
985
|
+
|
|
986
|
+
### Response
|
|
987
|
+
|
|
988
|
+
The response contains detailed information about the transaction status, type, and associated metadata. It also includes the array `"legs"` which represent the different stages or components of the transaction.
|
|
989
|
+
|
|
990
|
+
#### Response Fields:
|
|
991
|
+
|
|
992
|
+
<table><thead><tr><th width="219">Field</th><th width="119">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>chainId</code></td><td><code>string</code></td><td>The chain ID where the transaction occurred.</td></tr><tr><td><code>hash</code></td><td><code>string</code></td><td>The transaction hash.</td></tr><tr><td><code>block</code></td><td><code>number</code></td><td>The block number where the transaction was included.</td></tr><tr><td><code>type</code></td><td><code>string</code></td><td>The type of the transaction (e.g., <code>swap</code>, <code>token_transfer</code>).</td></tr><tr><td><code>status</code></td><td><code>string</code></td><td>The transaction status (e.g., <code>completed</code>).<br>We will expand on it <a href="#transaction-status">later</a>.</td></tr><tr><td><code>trackingStatus</code></td><td><code>string</code></td><td>The current tracking status (using <code>status</code> is enough and this field should not be necessary).</td></tr><tr><td><code>fromAsset</code></td><td><code>string</code></td><td>The asset being sent.</td></tr><tr><td><code>fromAmount</code></td><td><code>string</code></td><td>The amount of <code>fromAsset</code>.</td></tr><tr><td><code>fromAddress</code></td><td><code>string</code></td><td>The address sending the asset.</td></tr><tr><td><code>toAsset</code></td><td><code>string</code></td><td>The asset being received.</td></tr><tr><td><code>toAmount</code></td><td><code>string</code></td><td>The amount of <code>toAsset</code>.</td></tr><tr><td><code>toAddress</code></td><td><code>string</code></td><td>The recipient address.</td></tr><tr><td><code>finalisedAt</code></td><td><code>number</code></td><td>UNIX timestamp indicating when the transaction finalized.</td></tr><tr><td><code>meta</code></td><td><code>object</code></td><td>Metadata including images and provider info.</td></tr><tr><td><code>payload</code></td><td><code>object</code></td><td>Additional transaction specific data.</td></tr><tr><td><code>legs</code></td><td><code>array</code></td><td>Detailed breakdown of each transaction leg.</td></tr></tbody></table>
|
|
993
|
+
|
|
994
|
+
***
|
|
995
|
+
|
|
996
|
+
#### Example response:
|
|
997
|
+
|
|
998
|
+
```json
|
|
999
|
+
{
|
|
1000
|
+
"chainId": "43114",
|
|
1001
|
+
"hash": "0x18f6d7b91ceffcc6d70b5d73f324198d9847531b7fe53d9446b7e60a64fa44b9",
|
|
1002
|
+
"block": 57181100,
|
|
1003
|
+
"type": "swap",
|
|
1004
|
+
"status": "completed",
|
|
1005
|
+
"trackingStatus": "completed",
|
|
1006
|
+
"fromAsset": "AVAX.AVAX",
|
|
1007
|
+
"fromAmount": "9.58",
|
|
1008
|
+
"fromAddress": "0xC935B2397f0c6f85235ceFba2Eb714fb5F919Ca0",
|
|
1009
|
+
"toAsset": "THOR.RUNE",
|
|
1010
|
+
"toAmount": "0",
|
|
1011
|
+
"toAddress": "thor1mse4ysqpru6s7f6twlskt2yz963xz630mwtxqn",
|
|
1012
|
+
"finalisedAt": 1739313043,
|
|
1013
|
+
"meta": {
|
|
1014
|
+
"provider": "THORCHAIN",
|
|
1015
|
+
"providerAction": "swap",
|
|
1016
|
+
"images": {
|
|
1017
|
+
"from": "https://storage.googleapis.com/token-list-swapkit/images/avax.avax.png",
|
|
1018
|
+
"to": "https://storage.googleapis.com/token-list-swapkit/images/thor.rune.png",
|
|
1019
|
+
"provider": "https://storage.googleapis.com/token-list-swapkit/images/thor.rune.png",
|
|
1020
|
+
"chain": "https://storage.googleapis.com/token-list-swapkit/avax.avax.png"
|
|
1021
|
+
}
|
|
1022
|
+
},
|
|
1023
|
+
"payload": {
|
|
1024
|
+
"memo": "=:r:thor1mse4ysqpru6s7f6twlskt2yz963xz630mwtxqn:0:-_/t:5/50"
|
|
1025
|
+
},
|
|
1026
|
+
"legs": [
|
|
1027
|
+
{
|
|
1028
|
+
"chainId": "43114",
|
|
1029
|
+
"hash": "0x18f6d7b91ceffcc6d70b5d73f324198d9847531b7fe53d9446b7e60a64fa44b9",
|
|
1030
|
+
"block": 57181100,
|
|
1031
|
+
"type": "swap",
|
|
1032
|
+
"status": "completed",
|
|
1033
|
+
"trackingStatus": "completed",
|
|
1034
|
+
"fromAsset": "AVAX.AVAX",
|
|
1035
|
+
"fromAmount": "9.58",
|
|
1036
|
+
"fromAddress": "0xC935B2397f0c6f85235ceFba2Eb714fb5F919Ca0",
|
|
1037
|
+
"toAsset": "AVAX.AVAX",
|
|
1038
|
+
"toAmount": "9.58",
|
|
1039
|
+
"toAddress": "0x8F66c4AE756BEbC49Ec8B81966DD8bba9f127549",
|
|
1040
|
+
"finalisedAt": 1739313038,
|
|
1041
|
+
"meta": {
|
|
1042
|
+
"images": {
|
|
1043
|
+
"from": "https://storage.googleapis.com/token-list-swapkit/images/avax.avax.png",
|
|
1044
|
+
"to": "https://storage.googleapis.com/token-list-swapkit/images/avax.avax.png",
|
|
1045
|
+
"chain": "https://storage.googleapis.com/token-list-swapkit/avax.avax.png"
|
|
1046
|
+
}
|
|
1047
|
+
},
|
|
1048
|
+
"payload": {
|
|
1049
|
+
"memo": "=:r:thor1mse4ysqpru6s7f6twlskt2yz963xz630mwtxqn:0:-_/t:5/50"
|
|
1050
|
+
}
|
|
1051
|
+
},
|
|
1052
|
+
{
|
|
1053
|
+
"chainId": "thorchain-1",
|
|
1054
|
+
"hash": "18f6d7b91ceffcc6d70b5d73f324198d9847531b7fe53d9446b7e60a64fa44b9",
|
|
1055
|
+
"block": 19828318,
|
|
1056
|
+
"type": "swap",
|
|
1057
|
+
"status": "completed",
|
|
1058
|
+
"trackingStatus": "completed",
|
|
1059
|
+
"fromAsset": "AVAX.AVAX",
|
|
1060
|
+
"fromAmount": "9.58",
|
|
1061
|
+
"fromAddress": "0xc935b2397f0c6f85235cefba2eb714fb5f919ca0",
|
|
1062
|
+
"toAsset": "THOR.RUNE",
|
|
1063
|
+
"toAmount": "0",
|
|
1064
|
+
"toAddress": "thor1mse4ysqpru6s7f6twlskt2yz963xz630mwtxqn",
|
|
1065
|
+
"finalisedAt": 1739313043,
|
|
1066
|
+
"meta": {
|
|
1067
|
+
"provider": "THORCHAIN",
|
|
1068
|
+
"providerAction": "swap",
|
|
1069
|
+
"images": {
|
|
1070
|
+
"from": "https://storage.googleapis.com/token-list-swapkit/images/avax.avax.png",
|
|
1071
|
+
"to": "https://storage.googleapis.com/token-list-swapkit/images/thor.rune.png",
|
|
1072
|
+
"provider": "https://storage.googleapis.com/token-list-swapkit/images/thor.rune.png",
|
|
1073
|
+
"chain": "https://storage.googleapis.com/token-list-swapkit/thor.rune.png"
|
|
1074
|
+
}
|
|
1075
|
+
},
|
|
1076
|
+
"payload": {
|
|
1077
|
+
"memo": "=:r:thor1mse4ysqpru6s7f6twlskt2yz963xz630mwtxqn:0:-_/t:5/50",
|
|
1078
|
+
"thorname": ""
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
]
|
|
1082
|
+
}
|
|
1083
|
+
```
|
|
1084
|
+
|
|
1085
|
+
***
|
|
1086
|
+
|
|
1087
|
+
#### Notes:
|
|
1088
|
+
|
|
1089
|
+
* The `legs` array provides a detailed view of each step in the transaction process.
|
|
1090
|
+
* `meta` contains additional information, including images and the swap provider details.
|
|
1091
|
+
* The `payload` may include data like `evmCalldata` or `memo` for more complex transactions.
|
|
1092
|
+
|
|
1093
|
+
### Transaction status
|
|
1094
|
+
|
|
1095
|
+
An important part of the response is the transaction status from the `status` field, which can have multiple values:
|
|
1096
|
+
|
|
1097
|
+
<table><thead><tr><th width="154">Status value</th><th>Explanation</th></tr></thead><tbody><tr><td><code>not_started</code></td><td>The swap has not happened yet.</td></tr><tr><td><code>pending</code></td><td>Intermediate state. The transaction has been detected by the mempool but is pending block confirmation.</td></tr><tr><td><code>swapping</code></td><td>The swap is happening.</td></tr><tr><td><code>completed</code></td><td>The swap is finished.</td></tr><tr><td><code>refunded</code></td><td>The swap was refunded because of the slippage settings.</td></tr><tr><td><code>unknown</code></td><td>Catch all for other situations.</td></tr><tr><td><code>failed</code></td><td>The transaction failed in an inbound EVM contract.</td></tr></tbody></table>
|
|
1098
|
+
|
|
1099
|
+
# /screen - Check AML compliance
|
|
1100
|
+
|
|
1101
|
+
### Endpoint
|
|
1102
|
+
|
|
1103
|
+
**Method:** `POST` \
|
|
1104
|
+
**URL:** `https://api.swapkit.dev/screen`
|
|
1105
|
+
|
|
1106
|
+
The `/screen` endpoint is used to check the Anti-Money Laundering (AML) compliance status of cryptocurrency addresses. It evaluates the risk level of the provided addresses across different blockchain networks using external compliance providers.
|
|
1107
|
+
|
|
1108
|
+
We periodically update our own database of blacklisted addresses sourced from trusted providers, and any `/quote` request that involves addresses previously identified as non-compliant will not receive quotes. Despite that, you can choose to screen addresses after a quote to see if their status has changed.
|
|
1109
|
+
|
|
1110
|
+
The endpoint provides a compliance confirmation. Our own database is updated with the result if the address is considered risky and it won't receive further quotes.\
|
|
1111
|
+
As an integrator, you can use this endpoint to check the addresses that interact with you. 
|
|
1112
|
+
|
|
1113
|
+
***
|
|
1114
|
+
|
|
1115
|
+
#### Request parameters
|
|
1116
|
+
|
|
1117
|
+
The request body should be a JSON object containing:
|
|
1118
|
+
|
|
1119
|
+
* `"addresses"`: A single address (string) or multiple addresses (array of strings).
|
|
1120
|
+
* `"chains"`: The blockchain chain ID relevant to each address. You can [see them here](https://docs.swapkit.dev/providers-request-supported-chains-by-a-swap-provider#chain-ids-and-corresponding-names), where we listed them before. They are standard identification for each chain.
|
|
1121
|
+
|
|
1122
|
+
{% tabs %}
|
|
1123
|
+
{% tab title="One address" %}
|
|
1124
|
+
|
|
1125
|
+
```json
|
|
1126
|
+
{
|
|
1127
|
+
"addresses": "0x2e1c9b2670802fDE14A789071b6703fe29bfbbFF",
|
|
1128
|
+
"chains": "1"
|
|
1129
|
+
}
|
|
1130
|
+
```
|
|
1131
|
+
|
|
1132
|
+
{% endtab %}
|
|
1133
|
+
|
|
1134
|
+
{% tab title="Multiple addresses" %}
|
|
1135
|
+
|
|
1136
|
+
```json
|
|
1137
|
+
{
|
|
1138
|
+
"addresses": [
|
|
1139
|
+
"0x2e1c9b2670802fDE14A789071b6703fe29bfbbFF",
|
|
1140
|
+
"bc1qh56gtgsp3j088cwpzdezcg5lptnv869vh8jjf2"
|
|
1141
|
+
],
|
|
1142
|
+
"chains": ["1", "bitcoin"]
|
|
1143
|
+
}
|
|
1144
|
+
```
|
|
1145
|
+
|
|
1146
|
+
{% endtab %}
|
|
1147
|
+
{% endtabs %}
|
|
1148
|
+
|
|
1149
|
+
### Response
|
|
1150
|
+
|
|
1151
|
+
The response contains a boolean field named `"isRisky"` that indicates whether the provided addresses are flagged for anti-money laundering (AML) concerns.
|
|
1152
|
+
|
|
1153
|
+
* If the value is `"isRisky": false`, the addresses have passed the compliance check.
|
|
1154
|
+
* If the value is `"isRisky": true`, at least one of the addresses has been flagged for AML concerns.
|
|
1155
|
+
|
|
1156
|
+
The response includes other parameters that internally help provide the source of the flag, but `"isRisky"` aggregates them.
|
|
1157
|
+
|
|
1158
|
+
### Important Considerations
|
|
1159
|
+
|
|
1160
|
+
1. Screening criteria:
|
|
1161
|
+
* The endpoint evaluates all addresses together and returns a single decision.
|
|
1162
|
+
* Even if one address is compliant, if any other address in the request is flagged the entire request may receive a `true` response.
|
|
1163
|
+
2. Dynamic compliance checking:
|
|
1164
|
+
* Passing a compliance check at one point does not guarantee future compliance.
|
|
1165
|
+
* If an address was screened while it had no funds, it should be re-screened after receiving funds, as they may originate from tainted sources.
|
|
1166
|
+
3. Decision responsibility:
|
|
1167
|
+
* SwapKit does not make the final decision on whether a trade is executed.
|
|
1168
|
+
* The integrator using this API is responsible for enforcing compliance policies based on the response.
|
|
1169
|
+
|
|
1170
|
+
\
|
|
1171
|
+
This endpoint is not meant to be called on every `/quote`. Instead, you should only screen the addresses involved when the user has indicated intent to swap, before they sign the transaction. \
|
|
1172
|
+
\
|
|
1173
|
+
All addresses involved in the trade should be included in the request, and they should be re-checked if a new trade is offered or if the balances of the addresses have changed since they last passed AML compliance.
|
|
1174
|
+
|
|
1175
|
+
***
|
|
1176
|
+
|
|
1177
|
+
Here is an example request:
|
|
1178
|
+
|
|
1179
|
+
```sh
|
|
1180
|
+
curl -X 'POST' \
|
|
1181
|
+
'https://api.swapkit.dev/screen' \
|
|
1182
|
+
-H 'Content-Type: application/json' \
|
|
1183
|
+
-H "x-api-key: YOUR_VARIABLE_HERE" \
|
|
1184
|
+
-d '{
|
|
1185
|
+
"addresses": [
|
|
1186
|
+
"0x2e1c9b2670802fDE14A789071b6703fe29bfbbFF",
|
|
1187
|
+
"bc1qh56gtgsp3j088cwpzdezcg5lptnv869vh8jjf2"
|
|
1188
|
+
],
|
|
1189
|
+
"chains": ["1", "bitcoin"]
|
|
1190
|
+
}'
|
|
1191
|
+
```
|
|
1192
|
+
|
|
1193
|
+
# /price - Lookup token prices
|
|
1194
|
+
|
|
1195
|
+
### Endpoint
|
|
1196
|
+
|
|
1197
|
+
**Method:** `POST`\
|
|
1198
|
+
**URL:** `https://api.swapkit.dev/price` 
|
|
1199
|
+
|
|
1200
|
+
***
|
|
1201
|
+
|
|
1202
|
+
###  Request parameters
|
|
1203
|
+
|
|
1204
|
+
<table><thead><tr><th width="103">Parameter</th><th width="95">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>tokens</code></td><td><code>array</code></td><td>List of token identifiers to fetch price for. Each item is an object with an <code>identifier</code> field (e.g., <code>{ "identifier": "ETH.ETH" }</code>).</td></tr><tr><td><code>metadata</code></td><td><code>boolean</code></td><td>If <code>true</code>, includes extended CoinGecko metadata (currently always included, even if set to <code>false</code>).</td></tr></tbody></table>
|
|
1205
|
+
|
|
1206
|
+
{% hint style="info" %}
|
|
1207
|
+
Identifiers follow the format `Chain.Asset`, such as `ETH.ETH`, `BTC.BTC` or `SOL.SOL`, with the contract address added at the end when necessary, such as `ARB.PENDLE-0x0c880f6761F1af8d9Aa9C466984b80DAb9a8c9e8`.\
|
|
1208
|
+
This is the same formatting used in our `/quote` endpoint.
|
|
1209
|
+
{% endhint %}
|
|
1210
|
+
|
|
1211
|
+
***
|
|
1212
|
+
|
|
1213
|
+
### Example requests
|
|
1214
|
+
|
|
1215
|
+
{% tabs %}
|
|
1216
|
+
{% tab title="Multiple Tokens (cURL)" %}
|
|
1217
|
+
|
|
1218
|
+
```sh
|
|
1219
|
+
curl -X POST \
|
|
1220
|
+
'https://api.swapkit.dev/price' \
|
|
1221
|
+
-H 'Content-Type: application/json' \
|
|
1222
|
+
-H "x-api-key: YOUR_VARIABLE_HERE" \
|
|
1223
|
+
-d '{
|
|
1224
|
+
"tokens": [
|
|
1225
|
+
{ "identifier": "ETH.ETH" },
|
|
1226
|
+
{ "identifier": "BTC.BTC" },
|
|
1227
|
+
{ "identifier": "SOL.SOL" },
|
|
1228
|
+
{"identifier": "BSC.CAKE-0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82"}
|
|
1229
|
+
],
|
|
1230
|
+
"metadata": true
|
|
1231
|
+
}'
|
|
1232
|
+
```
|
|
1233
|
+
|
|
1234
|
+
{% endtab %}
|
|
1235
|
+
|
|
1236
|
+
{% tab title="Single Token (cURL)" %}
|
|
1237
|
+
|
|
1238
|
+
```sh
|
|
1239
|
+
curl -X POST \
|
|
1240
|
+
'https://api.swapkit.dev/price' \
|
|
1241
|
+
-H 'Content-Type: application/json' \
|
|
1242
|
+
-H "x-api-key: YOUR_VARIABLE_HERE" \
|
|
1243
|
+
-d '{
|
|
1244
|
+
"tokens": [
|
|
1245
|
+
{ "identifier": "ETH.ETH" }
|
|
1246
|
+
],
|
|
1247
|
+
"metadata": true
|
|
1248
|
+
}'
|
|
1249
|
+
```
|
|
1250
|
+
|
|
1251
|
+
{% endtab %}
|
|
1252
|
+
{% endtabs %}
|
|
1253
|
+
|
|
1254
|
+
***
|
|
1255
|
+
|
|
1256
|
+
### Response format
|
|
1257
|
+
|
|
1258
|
+
The endpoint returns an array of token price objects.
|
|
1259
|
+
|
|
1260
|
+
```json
|
|
1261
|
+
[
|
|
1262
|
+
{
|
|
1263
|
+
"identifier": "ETH.ETH",
|
|
1264
|
+
"provider": "",
|
|
1265
|
+
"cg": {
|
|
1266
|
+
"id": "ethereum",
|
|
1267
|
+
"name": "Ethereum",
|
|
1268
|
+
"market_cap": 197138665861,
|
|
1269
|
+
"total_volume": 12560864823,
|
|
1270
|
+
"price_change_24h_usd": -39.89,
|
|
1271
|
+
"price_change_percentage_24h_usd": -2.38,
|
|
1272
|
+
"sparkline_in_7d": [...],
|
|
1273
|
+
"timestamp": "2025-04-15T12:30:44.643Z"
|
|
1274
|
+
},
|
|
1275
|
+
"price_usd": 1653.61,
|
|
1276
|
+
"timestamp": 1744720254562
|
|
1277
|
+
}
|
|
1278
|
+
]
|
|
1279
|
+
```
|
|
1280
|
+
|
|
1281
|
+
For each token, it includes the following fields:
|
|
1282
|
+
|
|
1283
|
+
<table><thead><tr><th width="309">Field</th><th width="94">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>identifier</code></td><td><code>string</code></td><td>The token identifier you queried (e.g., <code>ETH.ETH</code>).</td></tr><tr><td><code>price_usd</code></td><td><code>number</code></td><td>The current price of the token in USD.</td></tr><tr><td><code>timestamp</code></td><td><code>number</code></td><td>Millisecond timestamp of the price fetch.</td></tr><tr><td><code>cg</code></td><td><code>object</code></td><td><em>(If <code>metadata: true</code> — currently always present)</em> CoinGecko metadata.</td></tr><tr><td>└─ <code>id</code></td><td><code>string</code></td><td>CoinGecko’s internal ID.</td></tr><tr><td>└─ <code>name</code></td><td><code>string</code></td><td>Full name of the token.</td></tr><tr><td>└─ <code>market_cap</code></td><td><code>number</code></td><td>Total market capitalization in USD.</td></tr><tr><td>└─ <code>total_volume</code></td><td><code>number</code></td><td>24-hour trading volume in USD.</td></tr><tr><td>└─ <code>price_change_24h_usd</code></td><td><code>number</code></td><td>Price change in absolute USD over the last 24 hours.</td></tr><tr><td>└─ <code>price_change_percentage_24h_usd</code></td><td><code>number</code></td><td>Percentage price change over the last 24 hours.</td></tr><tr><td>└─ <code>sparkline_in_7d</code></td><td><code>array</code></td><td>7-day price history (useful for drawing sparkline charts).</td></tr><tr><td>└─ <code>timestamp</code></td><td><code>string</code></td><td>Timestamp of the CoinGecko data.</td></tr></tbody></table>
|
|
1284
|
+
|
|
1285
|
+
When a token's price is not found, or the token name is not correctly specified, the endpoint will return a price of 0 USD for that token. Not how `ETH.HTE` is not a correct identifier so the example response here fails to return a correct price:
|
|
1286
|
+
|
|
1287
|
+
```json
|
|
1288
|
+
[
|
|
1289
|
+
{
|
|
1290
|
+
"identifier": "ETH.EHT",
|
|
1291
|
+
"provider": "",
|
|
1292
|
+
"price_usd": 0,
|
|
1293
|
+
"timestamp": 0
|
|
1294
|
+
}
|
|
1295
|
+
]
|
|
1296
|
+
```
|
|
1297
|
+
|
|
1298
|
+
|
|
1299
|
+
# /price - Lookup token prices
|
|
1300
|
+
|
|
1301
|
+
### Endpoint
|
|
1302
|
+
|
|
1303
|
+
**Method:** `POST`\
|
|
1304
|
+
**URL:** `https://api.swapkit.dev/price` 
|
|
1305
|
+
|
|
1306
|
+
***
|
|
1307
|
+
|
|
1308
|
+
###  Request parameters
|
|
1309
|
+
|
|
1310
|
+
<table><thead><tr><th width="103">Parameter</th><th width="95">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>tokens</code></td><td><code>array</code></td><td>List of token identifiers to fetch price for. Each item is an object with an <code>identifier</code> field (e.g., <code>{ "identifier": "ETH.ETH" }</code>).</td></tr><tr><td><code>metadata</code></td><td><code>boolean</code></td><td>If <code>true</code>, includes extended CoinGecko metadata (currently always included, even if set to <code>false</code>).</td></tr></tbody></table>
|
|
1311
|
+
|
|
1312
|
+
{% hint style="info" %}
|
|
1313
|
+
Identifiers follow the format `Chain.Asset`, such as `ETH.ETH`, `BTC.BTC` or `SOL.SOL`, with the contract address added at the end when necessary, such as `ARB.PENDLE-0x0c880f6761F1af8d9Aa9C466984b80DAb9a8c9e8`.\
|
|
1314
|
+
This is the same formatting used in our `/quote` endpoint.
|
|
1315
|
+
{% endhint %}
|
|
1316
|
+
|
|
1317
|
+
***
|
|
1318
|
+
|
|
1319
|
+
### Example requests
|
|
1320
|
+
|
|
1321
|
+
{% tabs %}
|
|
1322
|
+
{% tab title="Multiple Tokens (cURL)" %}
|
|
1323
|
+
|
|
1324
|
+
```sh
|
|
1325
|
+
curl -X POST \
|
|
1326
|
+
'https://api.swapkit.dev/price' \
|
|
1327
|
+
-H 'Content-Type: application/json' \
|
|
1328
|
+
-H "x-api-key: YOUR_VARIABLE_HERE" \
|
|
1329
|
+
-d '{
|
|
1330
|
+
"tokens": [
|
|
1331
|
+
{ "identifier": "ETH.ETH" },
|
|
1332
|
+
{ "identifier": "BTC.BTC" },
|
|
1333
|
+
{ "identifier": "SOL.SOL" },
|
|
1334
|
+
{"identifier": "BSC.CAKE-0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82"}
|
|
1335
|
+
],
|
|
1336
|
+
"metadata": true
|
|
1337
|
+
}'
|
|
1338
|
+
```
|
|
1339
|
+
|
|
1340
|
+
{% endtab %}
|
|
1341
|
+
|
|
1342
|
+
{% tab title="Single Token (cURL)" %}
|
|
1343
|
+
|
|
1344
|
+
```sh
|
|
1345
|
+
curl -X POST \
|
|
1346
|
+
'https://api.swapkit.dev/price' \
|
|
1347
|
+
-H 'Content-Type: application/json' \
|
|
1348
|
+
-H "x-api-key: YOUR_VARIABLE_HERE" \
|
|
1349
|
+
-d '{
|
|
1350
|
+
"tokens": [
|
|
1351
|
+
{ "identifier": "ETH.ETH" }
|
|
1352
|
+
],
|
|
1353
|
+
"metadata": true
|
|
1354
|
+
}'
|
|
1355
|
+
```
|
|
1356
|
+
|
|
1357
|
+
{% endtab %}
|
|
1358
|
+
{% endtabs %}
|
|
1359
|
+
|
|
1360
|
+
***
|
|
1361
|
+
|
|
1362
|
+
### Response format
|
|
1363
|
+
|
|
1364
|
+
The endpoint returns an array of token price objects.
|
|
1365
|
+
|
|
1366
|
+
```json
|
|
1367
|
+
[
|
|
1368
|
+
{
|
|
1369
|
+
"identifier": "ETH.ETH",
|
|
1370
|
+
"provider": "",
|
|
1371
|
+
"cg": {
|
|
1372
|
+
"id": "ethereum",
|
|
1373
|
+
"name": "Ethereum",
|
|
1374
|
+
"market_cap": 197138665861,
|
|
1375
|
+
"total_volume": 12560864823,
|
|
1376
|
+
"price_change_24h_usd": -39.89,
|
|
1377
|
+
"price_change_percentage_24h_usd": -2.38,
|
|
1378
|
+
"sparkline_in_7d": [...],
|
|
1379
|
+
"timestamp": "2025-04-15T12:30:44.643Z"
|
|
1380
|
+
},
|
|
1381
|
+
"price_usd": 1653.61,
|
|
1382
|
+
"timestamp": 1744720254562
|
|
1383
|
+
}
|
|
1384
|
+
]
|
|
1385
|
+
```
|
|
1386
|
+
|
|
1387
|
+
For each token, it includes the following fields:
|
|
1388
|
+
|
|
1389
|
+
<table><thead><tr><th width="309">Field</th><th width="94">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>identifier</code></td><td><code>string</code></td><td>The token identifier you queried (e.g., <code>ETH.ETH</code>).</td></tr><tr><td><code>price_usd</code></td><td><code>number</code></td><td>The current price of the token in USD.</td></tr><tr><td><code>timestamp</code></td><td><code>number</code></td><td>Millisecond timestamp of the price fetch.</td></tr><tr><td><code>cg</code></td><td><code>object</code></td><td><em>(If <code>metadata: true</code> — currently always present)</em> CoinGecko metadata.</td></tr><tr><td>└─ <code>id</code></td><td><code>string</code></td><td>CoinGecko’s internal ID.</td></tr><tr><td>└─ <code>name</code></td><td><code>string</code></td><td>Full name of the token.</td></tr><tr><td>└─ <code>market_cap</code></td><td><code>number</code></td><td>Total market capitalization in USD.</td></tr><tr><td>└─ <code>total_volume</code></td><td><code>number</code></td><td>24-hour trading volume in USD.</td></tr><tr><td>└─ <code>price_change_24h_usd</code></td><td><code>number</code></td><td>Price change in absolute USD over the last 24 hours.</td></tr><tr><td>└─ <code>price_change_percentage_24h_usd</code></td><td><code>number</code></td><td>Percentage price change over the last 24 hours.</td></tr><tr><td>└─ <code>sparkline_in_7d</code></td><td><code>array</code></td><td>7-day price history (useful for drawing sparkline charts).</td></tr><tr><td>└─ <code>timestamp</code></td><td><code>string</code></td><td>Timestamp of the CoinGecko data.</td></tr></tbody></table>
|
|
1390
|
+
|
|
1391
|
+
When a token's price is not found, or the token name is not correctly specified, the endpoint will return a price of 0 USD for that token. Not how `ETH.HTE` is not a correct identifier so the example response here fails to return a correct price:
|
|
1392
|
+
|
|
1393
|
+
```json
|
|
1394
|
+
[
|
|
1395
|
+
{
|
|
1396
|
+
"identifier": "ETH.EHT",
|
|
1397
|
+
"provider": "",
|
|
1398
|
+
"price_usd": 0,
|
|
1399
|
+
"timestamp": 0
|
|
1400
|
+
}
|
|
1401
|
+
]
|
|
1402
|
+
```
|
|
1403
|
+
|
|
1404
|
+
|
|
1405
|
+
# /price - Lookup token prices
|
|
1406
|
+
|
|
1407
|
+
### Endpoint
|
|
1408
|
+
|
|
1409
|
+
**Method:** `POST`\
|
|
1410
|
+
**URL:** `https://api.swapkit.dev/price` 
|
|
1411
|
+
|
|
1412
|
+
***
|
|
1413
|
+
|
|
1414
|
+
###  Request parameters
|
|
1415
|
+
|
|
1416
|
+
<table><thead><tr><th width="103">Parameter</th><th width="95">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>tokens</code></td><td><code>array</code></td><td>List of token identifiers to fetch price for. Each item is an object with an <code>identifier</code> field (e.g., <code>{ "identifier": "ETH.ETH" }</code>).</td></tr><tr><td><code>metadata</code></td><td><code>boolean</code></td><td>If <code>true</code>, includes extended CoinGecko metadata (currently always included, even if set to <code>false</code>).</td></tr></tbody></table>
|
|
1417
|
+
|
|
1418
|
+
{% hint style="info" %}
|
|
1419
|
+
Identifiers follow the format `Chain.Asset`, such as `ETH.ETH`, `BTC.BTC` or `SOL.SOL`, with the contract address added at the end when necessary, such as `ARB.PENDLE-0x0c880f6761F1af8d9Aa9C466984b80DAb9a8c9e8`.\
|
|
1420
|
+
This is the same formatting used in our `/quote` endpoint.
|
|
1421
|
+
{% endhint %}
|
|
1422
|
+
|
|
1423
|
+
***
|
|
1424
|
+
|
|
1425
|
+
### Example requests
|
|
1426
|
+
|
|
1427
|
+
{% tabs %}
|
|
1428
|
+
{% tab title="Multiple Tokens (cURL)" %}
|
|
1429
|
+
|
|
1430
|
+
```sh
|
|
1431
|
+
curl -X POST \
|
|
1432
|
+
'https://api.swapkit.dev/price' \
|
|
1433
|
+
-H 'Content-Type: application/json' \
|
|
1434
|
+
-H "x-api-key: YOUR_VARIABLE_HERE" \
|
|
1435
|
+
-d '{
|
|
1436
|
+
"tokens": [
|
|
1437
|
+
{ "identifier": "ETH.ETH" },
|
|
1438
|
+
{ "identifier": "BTC.BTC" },
|
|
1439
|
+
{ "identifier": "SOL.SOL" },
|
|
1440
|
+
{"identifier": "BSC.CAKE-0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82"}
|
|
1441
|
+
],
|
|
1442
|
+
"metadata": true
|
|
1443
|
+
}'
|
|
1444
|
+
```
|
|
1445
|
+
|
|
1446
|
+
{% endtab %}
|
|
1447
|
+
|
|
1448
|
+
{% tab title="Single Token (cURL)" %}
|
|
1449
|
+
|
|
1450
|
+
```sh
|
|
1451
|
+
curl -X POST \
|
|
1452
|
+
'https://api.swapkit.dev/price' \
|
|
1453
|
+
-H 'Content-Type: application/json' \
|
|
1454
|
+
-H "x-api-key: YOUR_VARIABLE_HERE" \
|
|
1455
|
+
-d '{
|
|
1456
|
+
"tokens": [
|
|
1457
|
+
{ "identifier": "ETH.ETH" }
|
|
1458
|
+
],
|
|
1459
|
+
"metadata": true
|
|
1460
|
+
}'
|
|
1461
|
+
```
|
|
1462
|
+
|
|
1463
|
+
{% endtab %}
|
|
1464
|
+
{% endtabs %}
|
|
1465
|
+
|
|
1466
|
+
***
|
|
1467
|
+
|
|
1468
|
+
### Response format
|
|
1469
|
+
|
|
1470
|
+
The endpoint returns an array of token price objects.
|
|
1471
|
+
|
|
1472
|
+
```json
|
|
1473
|
+
[
|
|
1474
|
+
{
|
|
1475
|
+
"identifier": "ETH.ETH",
|
|
1476
|
+
"provider": "",
|
|
1477
|
+
"cg": {
|
|
1478
|
+
"id": "ethereum",
|
|
1479
|
+
"name": "Ethereum",
|
|
1480
|
+
"market_cap": 197138665861,
|
|
1481
|
+
"total_volume": 12560864823,
|
|
1482
|
+
"price_change_24h_usd": -39.89,
|
|
1483
|
+
"price_change_percentage_24h_usd": -2.38,
|
|
1484
|
+
"sparkline_in_7d": [...],
|
|
1485
|
+
"timestamp": "2025-04-15T12:30:44.643Z"
|
|
1486
|
+
},
|
|
1487
|
+
"price_usd": 1653.61,
|
|
1488
|
+
"timestamp": 1744720254562
|
|
1489
|
+
}
|
|
1490
|
+
]
|
|
1491
|
+
```
|
|
1492
|
+
|
|
1493
|
+
For each token, it includes the following fields:
|
|
1494
|
+
|
|
1495
|
+
<table><thead><tr><th width="309">Field</th><th width="94">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>identifier</code></td><td><code>string</code></td><td>The token identifier you queried (e.g., <code>ETH.ETH</code>).</td></tr><tr><td><code>price_usd</code></td><td><code>number</code></td><td>The current price of the token in USD.</td></tr><tr><td><code>timestamp</code></td><td><code>number</code></td><td>Millisecond timestamp of the price fetch.</td></tr><tr><td><code>cg</code></td><td><code>object</code></td><td><em>(If <code>metadata: true</code> — currently always present)</em> CoinGecko metadata.</td></tr><tr><td>└─ <code>id</code></td><td><code>string</code></td><td>CoinGecko’s internal ID.</td></tr><tr><td>└─ <code>name</code></td><td><code>string</code></td><td>Full name of the token.</td></tr><tr><td>└─ <code>market_cap</code></td><td><code>number</code></td><td>Total market capitalization in USD.</td></tr><tr><td>└─ <code>total_volume</code></td><td><code>number</code></td><td>24-hour trading volume in USD.</td></tr><tr><td>└─ <code>price_change_24h_usd</code></td><td><code>number</code></td><td>Price change in absolute USD over the last 24 hours.</td></tr><tr><td>└─ <code>price_change_percentage_24h_usd</code></td><td><code>number</code></td><td>Percentage price change over the last 24 hours.</td></tr><tr><td>└─ <code>sparkline_in_7d</code></td><td><code>array</code></td><td>7-day price history (useful for drawing sparkline charts).</td></tr><tr><td>└─ <code>timestamp</code></td><td><code>string</code></td><td>Timestamp of the CoinGecko data.</td></tr></tbody></table>
|
|
1496
|
+
|
|
1497
|
+
When a token's price is not found, or the token name is not correctly specified, the endpoint will return a price of 0 USD for that token. Not how `ETH.HTE` is not a correct identifier so the example response here fails to return a correct price:
|
|
1498
|
+
|
|
1499
|
+
```json
|
|
1500
|
+
[
|
|
1501
|
+
{
|
|
1502
|
+
"identifier": "ETH.EHT",
|
|
1503
|
+
"provider": "",
|
|
1504
|
+
"price_usd": 0,
|
|
1505
|
+
"timestamp": 0
|
|
1506
|
+
}
|
|
1507
|
+
]
|
|
1508
|
+
```
|