getBalance static method

Future<ICPTs> getBalance({
  1. required AgentFactory agent,
  2. required String accountId,
  3. SignIdentity? identity,
})

Implementation

static Future<ICPTs> getBalance({
  required AgentFactory agent,
  required String accountId,
  SignIdentity? identity,
}) async {
  try {
    var ledgerInstance = Ledger.hook(agent)..setIdentity(identity);
    var res =
        await ledgerInstance.agent.actor!.getFunc(LedgerMethods.getBalance)!(
            [AccountBalanceArgs(account: accountId).toJson()]);

    if (res != null) {
      return ICPTs.fromMap(res);
    }
    throw "Cannot get count but $res";
  } catch (e) {
    rethrow;
  }
}