Class TokenAPI

Represents a class for handling Token operations related to the voidnode server.

Hierarchy

  • BaseAPI
    • TokenAPI

Constructors

Properties

premia: Premia

The Premia SDK instance.

streamIndex: number = 0

The current index of quote streams. Used to cancel stale streams.

Methods

  • Cancels all ongoing streams.

    Returns Promise<void>

  • Fetches the current spot price of a given token in USD.

    This function retrieves the spot price for a given token from the underlying data source. If the token's USD price is not available, an error is thrown.

    Throws

    An error if the USD price for the token is not found.

    Parameters

    • address: string

      The address of the token for which to fetch the spot price.

    Returns Promise<bigint>

    A promise that resolves to the spot price of the token in USD.

  • Fetches information of a given token from voidnode, coingecko, or token contract.

    Throws

    Will throw an error if the token information cannot be fetched from either the voidnode server, coingecko, or token contract.

    Parameters

    • address: string

      The address of the token for which to fetch the detailed information.

    • Optional provider: Provider

      The custom provider to use for this call.

    Returns Promise<Token>

    A promise that resolves to an object containing the token's name, symbol, decimals, whether it's native or wrapped native, price in ETH and USD, address, and chain ID.

  • Fetches extended information of a given token from the voidnode server.

    Parameters

    • address: string

      The address of the token for which to fetch the extended information.

    Returns Promise<TokenExtended>

    A promise that resolves to an object containing the extended information of the token.

  • Retrieves the information for a list of tokens given their details.

    This function fetches information for multiple tokens specified by an array of token information objects. If voidnode querying is not skipped and fails, the function resorts to fetching token details directly.

    Throws

    Will throw an error if the voidnode server fails to load.

    Parameters

    • tokenList: TokenInfo[]

      An array of token information objects for which to fetch the token data.

    • Optional provider: Provider

      The custom provider to use for this call.

    Returns Promise<Token[]>

    A promise that resolves to an array containing the information of the specified tokens.

  • Retrieves the extended information for a list of tokens given their details.

    This function fetches extended information for multiple tokens specified by an array of token information objects.

    Parameters

    • tokenList: TokenInfo[]

      An array of token information objects for which to fetch the token data.

    Returns Promise<TokenExtended[]>

    A promise that resolves to an array containing the extended information of the specified tokens.

  • Fetches minimal information of a given token including its symbol and decimals.

    Parameters

    • address: string

      The address of the token for which to fetch the minimal information.

    • Optional provider: Provider

      The custom provider to use for this call.

    Returns Promise<TokenMinimal>

    A promise that resolves to an object containing the token's address, symbol, and decimals.

  • Fetches information for multiple tokens given their addresses.

    This function retrieves information for multiple tokens specified by an array of addresses. It uses caching with an hourly time to live to prevent frequent calls to the voidnode server. If voidnode call fails, it switches to skip the voidnode server and fetches the tokens' information directly.

    Parameters

    • tokens: string[]

      An array of token addresses for which to fetch the information.

    • Optional provider: Provider

      The custom provider to use for this call.

    Returns Promise<Token[]>

    A promise that resolves to an array containing the information of the tokens.

  • Retrieves extended information of multiple tokens given their addresses.

    Parameters

    • tokens: string[]

      An array of token addresses for which to fetch the extended information.

    Returns Promise<TokenExtended[]>

    A promise that resolves to an array containing the extended information of the specified tokens.

  • Checks if the given address corresponds to the native token on the current chain.

    Parameters

    • address: string

      The address to check.

    Returns boolean

    True if the address corresponds to the native token; otherwise false.

  • Checks if the given address corresponds to the wrapped native token on the current chain.

    Parameters

    • address: string

      The address to check.

    Returns boolean

    True if the address corresponds to the wrapped native token; otherwise false.

Generated using TypeDoc