getBalance method

Future<DC<Exception, BigInt>> getBalance(
  1. String tokenAddress,
  2. String address
)

Implementation

Future<DC<Exception, BigInt>> getBalance(
  String tokenAddress,
  String address,
) async {
  if (tokenAddress.toLowerCase() ==
      Variables.NATIVE_TOKEN_ADDRESS.toLowerCase()) {
    return _getNativeBalance(address);
  }
  try {
    final List<dynamic> response = await ContractsUtils.readFromContract(
      web3client,
      'ERC20',
      EthereumAddress.fromHex(tokenAddress),
      'balanceOf',
      [EthereumAddress.fromHex(address)],
    );
    return DC.data(response.first);
  } catch (e) {
    return DC.error(Exception(e.toString()));
  }
}