Documentation Index
Fetch the complete documentation index at: https://docs.li.fi/llms.txt
Use this file to discover all available pages before exploring further.
有关费用如何工作、不同链上的费用收集以及设置费用钱包的更多详细信息,请参阅货币化集成指南。
使用 LI.FI SDK 时,您可以通过从通过您的应用程序处理的交易中收取费用来货币化您的集成。SDK 支持以两种方式配置费用:在创建 SDK 配置时全局配置,或通过路由选项按请求配置。
全局费用配置
推荐的方法是在使用 createConfig 创建 SDK 配置时全局配置费用。这确保所有请求自动使用相同的费用配置:
import { createConfig } from "@lifi/sdk";
const config = createConfig({
integrator: "Your dApp/company name",
routeOptions: {
fee: 0.01, // 对所有请求应用 1% 的费用
},
// 其他选项...
});
使用此配置,所有路由请求、报价和合约调用将自动包含指定的费用,无需将其添加到每个单独的请求中。
按请求配置费用
或者,您可以按请求配置费用。当您需要为不同类型的交易或用户设置不同的费率时,这很有用。在请求路由或报价时,可以将 fee 参数添加到 options 对象。
带费用的基本路由请求
import { getRoutes } from "@lifi/sdk";
const routesRequest: RoutesRequest = {
fromChainId: 42161, // Arbitrum
toChainId: 10, // Optimism
fromTokenAddress: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831", // USDC on Arbitrum
toTokenAddress: "0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1", // DAI on Optimism
fromAmount: "10000000", // 10 USDC
options: {
integrator: "Your dApp/company name",
fee: 0.01, // 1% 费用
},
};
const result = await getRoutes(routesRequest);
const routes = result.routes;
带费用的报价请求
import { getQuote } from "@lifi/sdk";
const quoteRequest: QuoteRequest = {
fromChain: 42161, // Arbitrum
toChain: 10, // Optimism
fromToken: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831", // USDC on Arbitrum
toToken: "0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1", // DAI on Optimism
fromAmount: "10000000", // 10 USDC
fromAddress: "0x552008c0f6870c2f77e5cC1d2eb9bdff03e30Ea0",
integrator: "Your dApp/company name",
fee: 0.01, // 1% 费用
};
const quote = await getQuote(quoteRequest);