Skip to main content

Create Client

To get started, you need to create an SDK client for the LI.FI SDK. This client contains the shared settings and data required for the proper functioning of other SDK features that developers will use. The client can be configured with providers and used throughout your application.
import { createClient } from '@lifi/sdk';

const client = createClient({
  integrator: 'Your dApp/company name',
});

Parameters

ParameterRequiredDefaultDescription
integratorYesLI.FI SDK requires an integrator option to identify partners and allows them to monitor their activity on the partner dashboard, such as the transaction volume, enabling better management and support. Usually, the integrator option is your dApp or company name. This string must consist only of letters, numbers, hyphens, underscores, and dots and be a maximum of 23 characters long.
apiKeyNoUnique API key for accessing LI.FI API services. Necessary for higher rate limits. Read more Rate Limits & API Key
apiUrlNohttps://li.quest/v1The base URL for the LI.FI API. This is the endpoint through which all API requests are routed. It can be changed to the staging environment to test new features, for example.
userIdNoA unique identifier for the user of your application. This can be used to track user-specific data and interactions within the LI.FI.
routeOptionsNoCustom options for routing, applied when using getQuote, getRoutes, and getContractCallsQuote endpoints. These options can be configured once during SDK initialization or passed each time those functions are called.
rpcUrlsNoA mapping of chain IDs to arrays of RPC URLs. These URLs might be used for transaction execution and data retrieval.
providersNoAn array of SDK providers (e.g., EthereumProvider(), SolanaProvider()). Providers can also be set later using client.setProviders().
executionOptionsNoDefault execution options applied to all route executions. Individual executions can override these options.
preloadChainsNotrueA flag to enable preloading of chain data. When enabled, chains are fetched from the API on client creation.
chainsRefetchIntervalNoInterval in milliseconds to refetch chain data from the API.
disableVersionCheckNofalseA flag to disable version checking of the SDK. By default, the SDK checks its version on initialization and logs a message in the console if a new version is available, prompting the user to update the SDK.
debugNofalseA flag to enable debug logging in the SDK.
requestInterceptorNoA function to intercept and modify outgoing API requests before they are sent.
storageNoA custom storage implementation for persisting SDK data (e.g., chain data, route execution state). Uses LocalStorageAdapter in browser environments and InMemoryStorage in Node.js by default.
To learn how to use routeOptions for monetization, including configuring fees, see the Monetize the SDK guide.
Setting up providers is not required if you are using the SDK solely to access the LI.FI API without quote/route SDK execution functionality and plan to handle the execution independently. Providers can be added later using the client.setProviders() method.

Setting custom RPC URLs

import { createClient, ChainId } from '@lifi/sdk';

const client = createClient({
  integrator: "Your dApp/company name",
  rpcUrls: {
    [ChainId.ARB]: ["https://arbitrum-example.node.com/"],
    [ChainId.SOL]: ["https://solana-example.node.com/"],
  },
});
In a production app, it is recommended to pass through your authenticated RPC provider URL (Alchemy, Infura, Ankr, etc).If no RPC URLs are provided, LI.FI SDK will default to public RPC providers.Public RPC endpoints (especially Solana) can sometimes rate-limit users depending on location or during periods of heavy load, leading to issues such as incorrectly displaying balances or errors with transaction simulation.

Client Methods

The SDK client provides various methods to access configuration and manage providers. All methods are called on the client instance.
import { createClient } from '@lifi/sdk';

const client = createClient({
  integrator: 'Your dApp/company name',
});

Client API

MethodDescription
configReturns the current SDK configuration (read-only).
providersReturns the array of configured providers (read-only).
getProvider(type: ChainType)Returns the provider for the specified chain type, or undefined if not found.
setProviders(providers: SDKProvider[])Sets the providers in the SDK client. If a provider already exists for a chain type, it will be updated with the new information.
setChains(chains: ExtendedChain[])Sets the chains in the SDK client. Useful for preloading or overriding chain data.
getChains()Returns a promise that resolves to the list of available chains.
getChainById(chainId: ChainId)Returns a promise that resolves to the chain configuration for the specified chain ID. Throws an error if the chain is not found.
getRpcUrls()Returns a promise that resolves to the RPC URLs mapping for all configured chains.
getRpcUrlsByChainId(chainId: ChainId)Returns a promise that resolves to the array of RPC URLs for the specified chain ID. Throws an error if no RPC URLs are found for the chain.

Example: Using Client Methods

import { createClient, ChainId } from '@lifi/sdk';

const client = createClient({
  integrator: "Your dApp/company name",
});

// Get all available chains
const chains = await client.getChains();

// Get a specific chain
const ethereumChain = await client.getChainById(ChainId.ETH);

// Get RPC URLs for all chains
const rpcUrls = await client.getRpcUrls();

// Get RPC URLs for a specific chain
const arbitrumRpcUrls = await client.getRpcUrlsByChainId(ChainId.ARB);

// Access configuration
console.log(client.config.integrator);
console.log(client.config.apiUrl);

// Set providers (see Configure SDK Providers section)
client.setProviders([
  // ... your providers
]);