1

i'm trying to get an accountId32 from a string. In fact , i received account address in a telegram message but i would like to use native method has of BTreeMap<AccountId32, u32>. anyone got an idea about how to do it ?

1 Answer 1

0

If I understand correctly you have an String and want to query a method that needs an AccountId type as a parameter. See the example to get the balance of an account with the method:

account(AccountId32): FrameSystemAccountInfo

You can query it using PolkadotJS like this:

 const ADDR = '167vSUfcfk6DPmFNbV5MJZUbacSgxNYs85YUmBhgXAFHj3fd';
 const accountInfo = await apiAt.query.system.account(ADDR);

You can see how PolkadotJS manages the AccountId type in its codebase: https://github.com/polkadot-js/api/blob/master/packages/types/src/generic/AccountId.ts

Update for your specific example:

The result.individual where you try to find the address is not an array of Account_id, is the Account_id and the points:

'111B8CxcmnWbuDLyGvgUmRezDCK1brRZmvUuQ6SrFdMyc3S': '84,480',

What I suggest you to do to compare with your String is the following:

    const eraRewardPoints = await api.query.staking.erasRewardPoints(era.getNumber());
    for (const [id, points] of eraRewardPoints.individual.entries()) {
      if (id.toString() === polkadotAdressInString) {
        console.log(id.toString());
        console.log(points.toHuman());
      }
    }
1
  • You're correct. So yeah, i will let it down the has method and do as you said. thanks a lot.
    – Greg
    Commented Mar 10, 2023 at 19:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.