Getting all possible Connections
A connection is a pair of two tokens (on the same chain or on different chains) that can be exchanged via our platform.
The full API documentation for our /connections endpoint can be found here.
After having gathered information about available chains and tokens, the next step could be to learn which transfers from one token to another are possible. We call those transfer possibilities "connections".
To get those connections we provide a /connections endpoint. It accepts filtering by fromChain, toChain, fromToken or toToken. Which combination of filters you want to use, is up to you. There is only one limitation:
Since we support many different chains with many different tokens, the connections endpoint has to be filtered to make sure the response size doesn't get too big.
For this reason, either fromChain or toChain has to be passed in the query.
1
const getConnections = async (fromChain, toChain, fromToken, toToken) => {
2
const result = await axios.get('https://li.quest/v1/connections', {
3
params: {
4
fromChain,
5
toChain,
6
fromToken,
7
toToken,
8
}
9
});
10
return result.data;
11
}
Copied!
For example if you want to know which tokens you can receive on Gnosis by sending out USDT on Polygon (https://li.quest/v1/connections?fromChain=POL&toChain=DAI&fromToken=USDT) you will get a response that looks the following:
1
{
2
"connections": [
3
{
4
"fromChainId": 137,
5
"toChainId": 100,
6
"fromTokens": [
7
{
8
"address": "0xc2132d05d31c914a87c6611c10748aeb04b58e8f",
9
"decimals": 6,
10
"symbol": "USDT",
11
"chainId": 137,
12
"coinKey": "USDT",
13
"name": "USDT",
14
"logoURI": "https://static.debank.com/image/matic_token/logo_url/0xc2132d05d31c914a87c6611c10748aeb04b58e8f/66eadee7b7bb16b75e02b570ab8d5c01.png",
15
"priceUSD": "1"
16
}
17
],
18
"toTokens": [
19
{
20
"address": "0x4ecaba5870353805a9f068101a40e0f32ed605c6",
21
"decimals": 6,
22
"symbol": "USDT",
23
"chainId": 100,
24
"coinKey": "USDT",
25
"name": "USDT",
26
"logoURI": "https://static.debank.com/image/xdai_token/logo_url/0x4ecaba5870353805a9f068101a40e0f32ed605c6/66eadee7b7bb16b75e02b570ab8d5c01.png",
27
"priceUSD": "1"
28
},
29
{
30
"address": "0x6a023ccd1ff6f2045c3309768ead9e68f978f6e1",
31
"decimals": 18,
32
"symbol": "ETH",
33
"chainId": 100,
34
"coinKey": "ETH",
35
"name": "ETH",
36
"logoURI": "https://static.debank.com/image/xdai_token/logo_url/0x6a023ccd1ff6f2045c3309768ead9e68f978f6e1/61844453e63cf81301f845d7864236f6.png",
37
"priceUSD": "3085.55"
38
},
39
... // more toTokens will be in this list
40
]
41
},
42
... // more connections will be in this list
43
]
44
}
Copied!
It is important to know that there can be multiple connections for the same fromChainId and toChainId pair. The reason for this is that we try to group the available tokens as much as possible to reduce redundancy, but not every token can be exchanged for every other token.

Scenario: Showing all possible connections based on a predefined destination token

Imagine the following scenario: You are a game that allows the players to buy custom skins using USDT on Polygon. To allow your players to swap their own assets into USDT, you integrate LI.FI.
In your user interface you now want to show your players a list of all tokens grouped by their chain that they can swap to USDT (on Polygon) in order to buy a skin:
1
const getAllPossibleConnections = async () => {
2
const result = await axios.get('https://li.quest/v1/connections', {
3
params: {
4
toChain: 'POL',
5
toToken: 'USDT',
6
}
7
});
8
return result.data.connections;
9
}
10
​
11
const possibleConnections = await getAllPossibleConnections();
12
​
13
const fromTokensByChain = {};
14
possibleConnections.forEach(connection => {
15
if (!fromTokensByChain[connection.fromChainId]) {
16
fromTokensByChain[connection.fromChainId] = [];
17
}
18
​
19
fromTokensByChain[connection.fromChainId].push(...connection.fromTokens);
20
});
Copied!
Now you should be able to simply render this list and provide a nice overview over the available exchange options.
If you don't feel like implementing all of that yourself and you happen to work in a JavaScript/TypeScript environment you should have a look at our SDK.
However, if you just want to include our beautiful widget into your application, head over to our Widget Documentation.