Class Tokens

The Tokens class provides the methods for fetching the information of any token that comply with the ERC-20 standard. These methods include:

  • getTokens method: You can use this method to retrieve detailed information about multiple tokens by providing their addresses.
  • getBalances method: By using this method, you can retrieve the balances of multiple tokens for the given holders addresses.
  • getAllowances method: This method enables you to retrieve the allowances of multiple tokens for the given holders and spender addresses.

To use the Tokens class, you need to create an instance of the DeFiData class first and wait for it to be ready. Then you can access the tokens property from the DeFiData instance.

Example

Here's an example of how the Tokens class can be used:

// Import the `DeFiData` library
import { DeFiData } from 'defidata';

// Create an instance of `DeFiData`
const defiData = new DeFiData();

// Wait for the library to be ready
await defiData.ready();

// Access the `Tokens` class
const tokens = defiData.tokens;

// Use the `Tokens` class...

Hierarchy

  • Tokens

Methods

  • Retrieve detailed information about multiple tokens by providing their addresses.

    Parameters

    • networkId: number

      The ID of the network where the tokens are located.

    • tokenAddresses: string[]

      The array with token addresses for which you want to retrieve the information.

    • options: {
          getPairs?: boolean;
          baseTokens?: Token[];
          extraBaseTokens?: string[];
          blockTag?: string | number | bigint;
      } = {}

      An optional object containing additional options.

      • Optional getPairs?: boolean

        Indicates whether to include the trading pairs inside the additional pairs property of the returned Token object.

      • Optional baseTokens?: Token[]

        An optional array of Token objects representing the base tokens to override the default base tokens for the specified network.

      • Optional extraBaseTokens?: string[]

        An optional array of token addresses representing the base tokens added to the default base tokens for the specified network.

      • Optional blockTag?: string | number | bigint

        The number of the block in which the query will run.

    Returns Promise<{
        [tokenAddress: string]: Token;
    }>

    A Promise that resolves to an object with key-value pairs representing multiple tokens with its associated information. Where the keys represent token addresses and the values are Token objects.

    Throws

    Throws a error if the library is not initialized.

    Throws

    Throws a type error if the network ID is invalid.

    Throws

    Throws a type error if tokenAddresses is not an array of token addresses.

    Remarks

    Depending on the options, the Token objects may include additional pairs property.

  • Retrieve the balances of multiple tokens for the given holders addresses.

    Parameters

    • networkId: number

      The network ID.

    • inputList: {
          token: string;
          holder: string;
      }[]

      An array of objects containing token and holder addresses.

    • options: {
          blockTag?: string | number | bigint;
      } = {}

      An optional object containing additional options.

      • Optional blockTag?: string | number | bigint

        The number of the block in which the query will run.

    Returns Promise<TokensBalances>

    A Promise that resolves to an TokensBalances object representing token balances for multiple tokens and holders.

    Throws

    Throws a error if the library is not initialized.

    Throws

    Throws a type error if the network ID is invalid.

    Throws

    Throws a type error if inputList is not an array of objects with the token and holder addresses.

  • Retrieve the allowances of multiple tokens for the given holders and spender addresses.

    Parameters

    • networkId: number

      The ID of the network where the tokens are located.

    • inputList: {
          token: string;
          holder: string;
          spender: string;
      }[]

      An array of objects containing token, holder, and spender information.

    • options: {
          blockTag?: string | number | bigint;
      } = {}

      An optional object containing additional options.

      • Optional blockTag?: string | number | bigint

        The number of the block in which the query will run.

    Returns Promise<TokensAllowances>

    A Promise that resolves to an TokensAllowances object representing token allowances for multiple tokens, holders and spenders.

    Throws

    Throws a error if the library is not initialized.

    Throws

    Throws a type error if the network ID is invalid.

    Throws

    Throws a type error if inputList is not an array of objects with the token, holder and spender addresses.

Generated using TypeDoc