Skip to main content

Get available tokens

getTokens

Retrieves a list of all available tokens on specified chains. Parameters
  • client (SDKClient): The SDK client instance.
  • params (TokensRequest, optional): Configuration for the requested tokens.
    • chains ((ChainId | ChainKey)[], optional): List of chain IDs or keys. If not specified, returns tokens on all available chains.
    • chainTypes (ChainType[], optional): List of chain types.
    • extended (boolean, optional): When true, returns TokensExtendedResponse with additional token data. Default: false.
    • minPriceUSD (number, optional): Minimum USD price filter for returned tokens.
    • orderBy (TokensSortOrder, optional): Sort order for the token list.
    • limit (number, optional): Maximum number of tokens to return.
    • search (string, optional): Search query to filter tokens by name or symbol.
    • tags (TokenTag[], optional): Filter tokens by tags.
  • options (RequestOptions, optional): Additional request options.
Returns A Promise that resolves to TokensResponse, or TokensExtendedResponse when extended: true is set.
Example

getToken

Fetches details about a specific token on a specified chain. Parameters
  • client (SDKClient): The SDK client instance.
  • chain (ChainKey | ChainId): ID or key of the chain that contains the token.
  • token (string): Address or symbol of the token on the requested chain.
  • options (RequestOptions, optional): Additional request options.
Returns A Promise that resolves to a TokenExtended object.
Example

Get token balance

Please ensure that you configure the SDK with EVM/Solana providers first. They are required to use this functionality. Additionally, it is recommended to provide your private RPC URLs, as public ones are used by default and may rate limit you for multiple requests, such as getting the balance of multiple tokens at once. Read more Configure SDK Providers.

getTokenBalance

Returns the balance of a specific token a wallet holds. Parameters
  • client (SDKClient): The SDK client instance.
  • walletAddress (string): A wallet address.
  • token (Token): A Token object.
Returns A Promise that resolves to a TokenAmount or null.
Example

getTokenBalances

Returns the balances for a list of tokens a wallet holds. Parameters
  • client (SDKClient): The SDK client instance.
  • walletAddress (string): A wallet address.
  • tokens (Token[]): A list of Token objects.
Returns A Promise that resolves to a list of TokenAmount objects.
Example

getTokenBalancesByChain

Queries the balances of tokens for a specific list of chains for a given wallet. Parameters
  • client (SDKClient): The SDK client instance.
  • walletAddress (string): A wallet address.
  • tokensByChain ([chainId: number]: Token[]): A list of Token objects organized by chain IDs.
Returns A Promise that resolves to an object containing the tokens and their amounts on different chains.
Example

getWalletBalances

Returns the balances of tokens a wallet holds across EVM chains using the LI.FI API. Parameters
  • client (SDKClient): The SDK client instance.
  • walletAddress (string): A wallet address.
  • options (RequestOptions, optional): Additional request options.
Returns A Promise that resolves to Record<number, WalletTokenExtended[]> — token balances organized by chain ID.
Example

Managing token allowance

Token allowance and approval functionalities are specific to EVM (Ethereum Virtual Machine) chains. It allows smart contracts to interact with ERC-20 tokens by approving a certain amount of tokens that a contract can spend from the user’s wallet. Please ensure that you configure the SDK with the EVM provider. It is required to use this functionality. Read more Configure SDK Providers.
Token allowance functions are exported from @lifi/sdk-provider-ethereum package. Make sure to install and import from the correct package.

getTokenAllowance

Fetches the current allowance for a specific token. Parameters
  • client (SDKClient): The SDK client instance.
  • token (BaseToken): The token for which to check the allowance.
  • ownerAddress (string): The owner of the token.
  • spenderAddress (string): The spender address that was approved.
Returns A Promise that resolves to a bigint representing the allowance or undefined if the token is a native token.
Example

getTokenAllowanceMulticall

Fetches the current allowance for a list of token/spender address pairs. Parameters
  • client (SDKClient): The SDK client instance.
  • ownerAddress (string): The owner of the tokens.
  • tokens (TokenSpender[]): A list of token and spender address pairs.
Returns A Promise that resolves to an array of TokenAllowance objects.
Example

setTokenAllowance

Sets the token allowance for a specific token and spender address. Parameters
  • client (SDKClient): The SDK client instance.
  • request (ApproveTokenRequest): The approval request.
    • walletClient (Client): The Viem client used to send the transaction.
    • token (BaseToken): The token for which to set the allowance.
    • spenderAddress (string): The address of the spender.
    • amount (bigint): The amount of tokens to approve.
Returns A Promise that resolves to a Hash representing the transaction hash or void if no transaction is needed (e.g., for native tokens).
Example

revokeTokenApproval

Revokes the token approval for a specific token and spender address. Parameters
  • client (SDKClient): The SDK client instance.
  • request (RevokeApprovalRequest): The revoke request.
    • walletClient (Client): The Viem client used to send the transaction.
    • token (BaseToken): The token for which to revoke the allowance.
    • spenderAddress (string): The address of the spender.
Returns A Promise that resolves to a Hash representing the transaction hash or void if no transaction is needed (e.g., for native tokens).
Example