accountBalance static method

Future<Tokens> accountBalance({
  1. required AgentFactory agent,
  2. required String accountIdOrPrincipal,
  3. SignIdentity? identity,
})

Implementation

static Future<Tokens> accountBalance({
  required AgentFactory agent,
  required String accountIdOrPrincipal,
  SignIdentity? identity,
}) async {
  try {
    var ledgerInstance = Ledger.hook(agent)..setIdentity(identity);
    var accountId = isHexString(accountIdOrPrincipal)
        ? (accountIdOrPrincipal).toU8a().toList()
        : Principal.fromText(accountIdOrPrincipal).toAccountID().toList();

    var res = await ledgerInstance.agent.actor!
            .getFunc(LedgerMethods.accountBalance)!(
        [AccountBalanceArgsNew(account: accountId).toJson()]);

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