dAppBooster
    Preparing search index...

    Function useTokenLists

    • Loads and processes token lists from configured sources

      Fetches tokens from multiple token list URLs defined in configuration, processes them to create a unified token list with these features:

      • Filters duplicate tokens (based on chain-address pair)
      • Validates tokens against schema requirements
      • Automatically adds native tokens for each chain
      • Organizes tokens by chainId for efficient lookup
      • Utilizes caching for performance optimization

      Returns TokensMap

      Object containing:

      Intended to be used with a Suspense wrapper as it uses useSuspenseQueries

      Uses infinite cache durations as token lists rarely change

      const TokenListComponent = () => {
      const { tokens, tokensByChainId } = useTokenLists();

      return (
      <div>
      <p>Total tokens: {tokens.length}</p>
      <p>Ethereum tokens: {tokensByChainId[1]?.length || 0}</p>
      </div>
      );
      };

      // With Suspense wrapper
      const App = () => (
      <Suspense fallback={<div>Loading token lists...</div>}>
      <TokenListComponent />
      </Suspense>
      );