Class TokenManager

The TokenList class is used to fetch and validate token lists.

Hierarchy

Constructors

Properties

cache: TokenListCache

Caches fetched results indefinitely

customTokens: TokenInfo[]
initialLoad: Promise<TokenList[]>
onTokensChange: (() => void)

Type declaration

    • (): void
    • Called whenever the cache, or custom tokens changes

      Returns void

Methods

  • Parameters

    • Optional network: number | "base" | "ethereum" | "arbitrum" | "polygon" | "arbitrum-sepolia"
      Optional
    • removeDuplicates: boolean = true

    Returns TokenInfo[]

    all tokens from all cached token lists

  • Finds the native token for a network

    Parameters

    • network: number | "base" | "ethereum" | "arbitrum" | "polygon" | "arbitrum-sepolia"

      the network from which to get the token

    Returns undefined | TokenInfo

    the native token if one exists, otherwise undefined

  • Parameters

    • address: string

      address of the token to get

    • network: number | "base" | "ethereum" | "arbitrum" | "polygon" | "arbitrum-sepolia"

      the network to get the token from

    • Optional find: ((t) => boolean)

      optional function to find the token with specific criteria

      Optional
        • (t): boolean
        • Parameters

          Returns boolean

    Returns TokenInfo

    the first occurence of the token with the given address, or undefined if not found

  • Type Parameters

    • Symbol extends string

    Parameters

    • symbol: Symbol

      symbol of the token to get

    • network: number | "base" | "ethereum" | "arbitrum" | "polygon" | "arbitrum-sepolia"

      the network to get the token from

    Returns TokenInfo & {
        symbol: Symbol;
    }

    the first occurence of the token with the given symbol, or undefined if not found

  • Returns an array of tokens with the given addresses. Order is not guaranteed. If a token cannot be found with the given address, it will be omitted from the array. If multiple tokens are found with the same address and network, they will all be included.

    Parameters

    • search: SearchTokenAddress[]

      an array of objects with address as the address of the token, and network as the network of the token

    Returns TokenInfo[]

    an array of tokens with the given addresses.

    Note

    this is not optimised for large addresses arrays

  • Returns an array of tokens with the given symbol. Order is not guaranteed. If a token cannot be found with the given address, it will be omitted from the array. If multiple tokens are found with the same address and network, they will all be included.

    Parameters

    • search: SearchTokenSymbols[]

      an array of objects with address as the address of the token, and network as the network of the token

    Returns TokenInfo[]

    an array of tokens with the given symbol.

    Note

    this is not optimised for large symbol arrays

  • Gets the wrapped native token for a network

    Parameters

    • network: number | "base" | "ethereum" | "arbitrum" | "polygon" | "arbitrum-sepolia"

      the network from which to get the token

    Returns TokenInfo

    the wrapped native token if one exists, otherwise undefined

  • Sets a cache key to a token list

    Parameters

    • key: string

      the key in the cache for which to set the tokenList

    • tokenList: TokenList

      the tokenList to set

    Returns void

  • Parameters

    • address: string

      address of the token to get

    • network: number | "base" | "ethereum" | "arbitrum" | "polygon" | "arbitrum-sepolia"

      the network to get the token from

    • Optional find: ((t) => boolean)

      optional function to find the token with specific criteria

      Optional
        • (t): boolean
        • Parameters

          Returns boolean

    Returns undefined | TokenInfo

    the first occurence of the token with the given address, or undefined if not found

  • Type Parameters

    • Symbol extends string

    Parameters

    • symbol: Symbol

      symbol of the token to get

    • network: number | "base" | "ethereum" | "arbitrum" | "polygon" | "arbitrum-sepolia"

      the network to get the token from

    Returns undefined | TokenInfo & {
        symbol: Symbol;
    }

    the first occurence of the token with the given symbol, or undefined if not found

  • Tries to get the wrapped native token for a network

    Parameters

    • network: number | "base" | "ethereum" | "arbitrum" | "polygon" | "arbitrum-sepolia"

      the network from which to get the token

    Returns undefined | TokenInfo

    the wrapped native token if one exists, otherwise undefined

Generated using TypeDoc