smartcontractsalgorand

How do I get Account Information Through Algorand TypeScript SDK?


So Basically I'm trying to get Account Information.

Method: Algodv2accountInformation,

returns the AccountInformation type, but after calling .do()

.i.e

Algodv2accountInformation.do()

the return type is a more generic

<Promise<Record<string, any>>

What is the right way to make this api call but have it return right Information.

<AccountInformation>


Solution

  • I just checked their docs, It is confusing as docs says it returns

    <AccountInformation>

    Algorand Account Information TypeScript

    Here's Link to docs

    <AccountInformation> is encapsulating request, not response.

    What you can do it leverage class, as it extends Base Class which does takes in Record<string,any> as input.

    So the JSON you get from running .do() on .

    accountInformation(account.addr).do():
    {
      address: 'LFNDB6ADWN7M3HFA7TSBKW4ZV7Q3TAJ2TWAGHH35WFGQAVGTJGFVJXQASI',
      amount: 10000000,
      'amount-without-pending-rewards': 10000000,
      'apps-local-state': [],
      'apps-total-schema': { 'num-byte-slice': 0, 'num-uint': 0 },
      assets: [],
      'created-apps': [],
      'created-assets': [],
      'min-balance': 100000,
      'pending-rewards': 0,
      'reward-base': 0,
      rewards: 0,
      round: 32,
      status: 'Offline',
      'total-apps-opted-in': 0,
      'total-assets-opted-in': 0,
      'total-created-apps': 0,
      'total-created-assets': 0
    }
    

    Could be passed to Account(Record<String, any>) as follows:

    new algosdk.modelsv2.Account(info):
    Account {
      address: 'LFNDB6ADWN7M3HFA7TSBKW4ZV7Q3TAJ2TWAGHH35WFGQAVGTJGFVJXQASI',
      amount: 10000000,
      amountWithoutPendingRewards: undefined,
      minBalance: undefined,
      pendingRewards: undefined,
      rewards: 0,
      round: 32,
      status: 'Offline',
      totalAppsOptedIn: undefined,
      totalAssetsOptedIn: undefined,
      totalCreatedApps: undefined,
      totalCreatedAssets: undefined,
      appsLocalState: undefined,
      appsTotalExtraPages: undefined,
      appsTotalSchema: undefined,
      assets: [],
      authAddr: undefined,
      createdApps: undefined,
      createdAssets: undefined,
      participation: undefined,
      rewardBase: undefined,
      sigType: undefined,
      attribute_map: {
        address: 'address',
        amount: 'amount',
        amountWithoutPendingRewards: 'amount-without-pending-rewards',
        minBalance: 'min-balance',
        pendingRewards: 'pending-rewards',
        rewards: 'rewards',
        round: 'round',
        status: 'status',
        totalAppsOptedIn: 'total-apps-opted-in',
        totalAssetsOptedIn: 'total-assets-opted-in',
        totalCreatedApps: 'total-created-apps',
        totalCreatedAssets: 'total-created-assets',
        appsLocalState: 'apps-local-state',
        appsTotalExtraPages: 'apps-total-extra-pages',
        appsTotalSchema: 'apps-total-schema',
        assets: 'assets',
        authAddr: 'auth-addr',
        createdApps: 'created-apps',
        createdAssets: 'created-assets',
        participation: 'participation',
        rewardBase: 'reward-base',
        sigType: 'sig-type'
      }
    }
    

    And! Voilla! you've got your account model object!

    Actually there should be some method .getModel(), I'll create a PR, as this should be part of SDK.