Module for handling ERC20 token-related operations on Conflux eSpace. Provides methods for querying token balances, supplies, and historical data.

TokenModule

Hierarchy (View Summary)

Constructors

Properties

baseUrl: string

Base URL for the API endpoints

apiKey?: string

Optional API key for authenticated requests

logger: Logger<never> = ...

Logger instance for token operations

Methods

  • Protected

    Makes an API request with the given parameters. Handles parameter sanitization, API key inclusion, and error handling.

    Type Parameters

    • T

      Type of the expected response data

    Parameters

    • endpoint: string

      API endpoint to call

    • params: Record<string, undefined | null | string | number | boolean> = {}

      Query parameters

    Returns Promise<ApiResponse<T>>

    Promise resolving to the API response

    When the API request fails or returns an error status

  • Get ERC20 token balance for an address. Retrieves the current balance of a specific ERC20 token for a given address.

    Parameters

    • params: TokenBalanceParams

      Parameters for the token balance query

      Parameters for token balance request Gets the current balance of a specific token for an account

      TokenBalanceParams

      • contractaddress: string

        Token contract address

      • address: string

        Account address to check balance for

    Returns Promise<string>

    The token balance

    If the address or contract address is invalid

  • Get ERC20 token total supply. Retrieves the current total supply of a specific ERC20 token.

    Parameters

    • params: TokenSupplyParams

      Parameters for the token supply query

      Parameters for token supply request Gets the current total supply of a token

      TokenSupplyParams

      • contractaddress: string

        Token contract address

    Returns Promise<string>

    The token total supply

    If the contract address is invalid

  • Get historical ERC20 token total supply at a specific block. Retrieves the total supply of a specific ERC20 token at a given block number.

    Parameters

    • params: TokenSupplyHistoryParams

      Parameters for the historical token supply query

      Parameters for historical token supply data Gets the total supply of a token at a specific block

      TokenSupplyHistoryParams

      • contractaddress: string

        Token contract address

      • address: string

        Account address to check balance for

      • blockno: number

        Block number to query supply at

    Returns Promise<string>

    The historical token supply

    If any of the parameters are invalid

  • Get historical ERC20 token balance for an account at a specific block number. Retrieves the balance of a specific ERC20 token for a given address at a specific block.

    Parameters

    • params: TokenBalanceHistoryParams

      Parameters for the historical balance query

      Parameters for token balance history Gets the balance of a token for an account at a specific block

      TokenBalanceHistoryParams

      • contractaddress: string

        Token contract address

      • address: string

        Account address to check balance for

      • blockno: number

        Block number to query balance at

    Returns Promise<string>

    The historical token balance

    If any of the parameters are invalid or missing