getAccountBalance method

Future<String> getAccountBalance(
  1. String accountId
)

Implementation

Future<String> getAccountBalance(
  String accountId,
) async {
  final res = await networkClient.postHTTP(
    '',
    {
      "jsonrpc": "2.0",
      "id": "dontcare",
      "method": "query",
      "params": {
        "request_type": "view_account",
        "finality": "final",
        "account_id": accountId
      }
    },
  );
  if (res.isSuccess) {
    final decodedRes = res.data['result']['amount'].toString();
    final nearAmount = NearFormatter.yoctoNearToNear(
      decodedRes,
    );
    return nearAmount;
  } else {
    return "Error while getting balance";
  }
}