跳转到主要内容
获取此刻可用选项(链、桥接器、DEX)的概述。

获取可用链

getChains

获取 SDK 支持的所有可用链的列表。 参数
  • params (ChainsRequest, 可选): 请求链的配置。
    • chainTypes (ChainType[], 可选): 链类型列表。
  • options (RequestOptions, 可选): 其他请求选项。
返回 返回解析为 ExtendedChain 对象数组的 Promise。
示例
import { ChainType, getChains } from '@lifi/sdk';

try {
  const chains = await getChains({ chainTypes: [ChainType.EVM] });
  console.log(chains);
} catch (error) {
  console.error(error);
}

获取可用的桥接器和 DEX

getTools

获取可用于桥接和交换代币的工具。 参数
  • params (ToolsRequest, 可选): 请求工具的配置。
    • chains ((ChainKey | ChainId)[], 可选): 链 ID 或键的列表。
  • options (RequestOptions, 可选): 其他请求选项。
返回 返回解析为 ToolsResponse 的 Promise,包含有关可用桥接器和 DEX 的信息。
示例
import { getTools } from '@lifi/sdk';

try {
  const tools = await getTools();
  console.log(tools);
} catch (error) {
  console.error(error);
}

获取可用连接

连接是可以通过我们的平台交换的一对两个代币(在同一链上或不同链上)。 阅读更多获取所有可能的连接

getConnections

获取交换或桥接代币的所有可用连接。 参数
  • connectionRequest (ConnectionsRequest): 连接请求的配置。
    • fromChain (number, 可选): 源链 ID。
    • fromToken (string, 可选): 源代币地址。
    • toChain (number, 可选): 目标链 ID。
    • toToken (string, 可选): 目标代币地址。
    • allowBridges (string[], 可选): 允许的桥接器。
    • denyBridges (string[], 可选): 拒绝的桥接器。
    • preferBridges (string[], 可选): 首选桥接器。
    • allowExchanges (string[], 可选): 允许的交易所。
    • denyExchanges (string[], 可选): 拒绝的交易所。
    • preferExchanges (string[], 可选): 首选交易所。
    • allowSwitchChain (boolean, 可选): 是否包含需要链切换(多个签名)的连接。默认为 true。
    • allowDestinationCall (boolean, 可选): 是否包含包括目标调用的连接。默认为 true。
    • chainTypes (ChainType[], 可选): 要包含的链类型。
  • options (RequestOptions, 可选): 请求选项。
返回 返回解析为 ConnectionsResponse 的 Promise。
示例
import { getConnections } from '@lifi/sdk';

const connectionRequest = {
  fromChain: 1,
  fromToken: '0x0000000000000000000000000000000000000000',
  toChain: 10,
  toToken: '0x0000000000000000000000000000000000000000',
};

try {
  const connections = await getConnections(connectionRequest);
  console.log('Connections:', connections);
} catch (error) {
  console.error('Error:', error);
}
有关每个端点及其响应的更详细信息,请参阅 LI.FI API 文档。
I