getNativeBalance method

Future<String?> getNativeBalance({
  1. required EvmChain chain,
  2. required String address,
})

Implementation

Future<String?> getNativeBalance({
  required EvmChain chain,
  required String address,
}) async {
  const int divideby = 1000000000000000000;
  final String chainn = EvmChainHelper.getChainName(chaintype: chain);
  try {
    final response =
        await _fetch("$address/balance", parameters: {"chain": chainn});
    final resData = jsonDecode(response.body);
    Constants.logger.d(resData);
    if (response.statusCode != 200) {
      Constants.logger.w(resData["message"]);
      throw resData["message"];
    } else {
      return (double.parse(resData["balance"].toString()) / divideby)
          .toStringAsFixed(8);
    }
  } catch (error) {
    Constants.logger.w(error);
    return null;
  }
}