dAppBooster
    Preparing search index...

    Function useTokens

    • Custom hook for fetching and managing tokens data with price and balances.

      Combines token list data with real-time price and balance information from LI.FI SDK. Features include:

      • Token data fetching from token lists
      • Balance fetching for specified accounts across multiple chains
      • Price information retrieval
      • Automatic sorting by token value (balance × price)
      • Periodic refetching for up-to-date balances and prices

      On chains not covered by LI.FI (e.g. Sepolia), balance fetching falls back to a direct on-chain multicall. In this mode priceUSD is absent from token extensions, so any UI that reads extensions.priceUSD should treat undefined as "N/A".

      Parameters

      • params: {
            account?: `0x${string}`;
            chainId?: number;
            sortByBalance?: boolean;
            withBalance?: boolean;
        } = ...

        Parameters for tokens fetching

        • Optionalaccount?: `0x${string}`

          Account address for balance fetching (defaults to connected wallet)

        • OptionalchainId?: number

          Specific chain ID to filter tokens (defaults to all supported chains)

        • OptionalsortByBalance?: boolean

          Whether to sort tokens by balance. When false, source order is preserved even if balances are fetched.

        • OptionalwithBalance?: boolean

          Whether to fetch token balances

      Returns {
          isLoadingBalances: boolean;
          isLoadingPrices: boolean;
          tokens: {
              address: string;
              chainId: number;
              decimals: number;
              extensions?: Record<
                  string,
                  | string
                  | number
                  | bigint
                  | boolean
                  | Record<
                      string,
                      | string
                      | number
                      | bigint
                      | boolean
                      | Record<string, string | number | bigint | boolean | null | undefined>
                      | null
                      | undefined,
                  >
                  | null
                  | undefined,
              >;
              logoURI?: string;
              name: string;
              symbol: string;
          }[];
          tokensByChainId: {
              [chainId: number]: {
                  address: string;
                  chainId: number;
                  decimals: number;
                  extensions?: Record<
                      string,
                      | string
                      | number
                      | bigint
                      | boolean
                      | Record<
                          string,
                          | string
                          | number
                          | bigint
                          | boolean
                          | Record<string, (...) | (...) | (...) | (...) | (...) | (...) | (...)>
                          | null
                          | undefined,
                      >
                      | null
                      | undefined,
                  >;
                  logoURI?: string;
                  name: string;
                  symbol: string;
              }[];
          };
      }

      Token data and loading state

      // Fetch all tokens with balances for connected wallet
      const { tokens, tokensByChainId, isLoadingBalances } = useTokens();

      // Fetch tokens for specific chain without balances
      const { tokens } = useTokens({
      chainId: 1,
      withBalance: false
      });

      // Fetch balances for specific account
      const { tokens } = useTokens({
      account: '0x123...'
      });