getBalance method

Future<BigInt> getBalance(
  1. EthereumAddress tokenAddress,
  2. EthereumAddress address
)

Retrieves the balance of a specified address for a given token.

This method fetches the balance of an address. If the token is native, it retrieves the native balance. Otherwise, it fetches the balance of the ERC20 token using the balanceOf function of the token's contract.

tokenAddress is the address of the token (either ERC20 or native). address is the address whose balance is to be retrieved.

Returns a BigInt representing the balance of the address for the specified token.

Implementation

Future<BigInt> getBalance(
  EthereumAddress tokenAddress,
  EthereumAddress address,
) async {
  if (ContractsUtils.isNativeToken(tokenAddress.toString())) {
    return _getNativeBalance(address);
  }

  return ContractsUtils.readFromContractWithFirstResult(
    client: wallet.proxy.client,
    contractName: 'ERC20',
    contractAddress: tokenAddress,
    methodName: 'balanceOf',
    params: [address],
  );
}