getAccount method

Future<Account?> getAccount(
  1. String accountId
)
inherited

Fetches a minimal set of current info about a Stellar account. Needed to get the current sequence number for the account, so you can build a successful transaction. Returns null if account was not found for the given accountId.

Implementation

Future<Account?> getAccount(String accountId) async {
  XdrLedgerKey ledgerKey = XdrLedgerKey(XdrLedgerEntryType.ACCOUNT);
  ledgerKey.account = XdrLedgerKeyAccount(
      XdrAccountID(KeyPair.fromAccountId(accountId).xdrPublicKey));
  GetLedgerEntriesResponse ledgerEntriesResponse =
      await getLedgerEntries([ledgerKey.toBase64EncodedXdrString()]);

  if (ledgerEntriesResponse.entries != null &&
      ledgerEntriesResponse.entries!.length > 0) {
    var accountEntry =
        ledgerEntriesResponse.entries![0].ledgerEntryDataXdr.account;
    if (accountEntry != null) {
      String accountId =
          KeyPair.fromXdrPublicKey(accountEntry.accountID.accountID)
              .accountId;
      BigInt seqNr = accountEntry.seqNum.sequenceNumber.bigInt;
      return Account(accountId, seqNr);
    }
  }
  return null;
}