0

How to convert account id string to AccountId primitives

let account = "5DJk1gegyQJk6BNs7LceZ1akt5e9fpm4gUYGzcfpKaLG9Mmb".to_owned();
let AccountId: T::AccountId = account;
Amiya Behera
  • 2,210
  • 19
  • 32

1 Answers1

0

You probably expose such things as hardcoded values in the code, but rather make them configurable. Also, the T::AccountId is generic and we don't make any assumption about it being SS58-compatible in any way (Note that AccountId32 is Ss58Codec, not T::AccountId). In that case, what you want is to parse the SS58 string in the top level runtime and pass it into the pallet as a config, which means this is a duplicate of: How to hardcode an address in the substrate runtime?

kianenigma
  • 1,365
  • 12
  • 20
  • But I want to enter accountId as dynamic, like passing as Vec string (concatenating AccountId + a string value), then getting the AccountId – Amiya Behera Apr 06 '21 at 11:17
  • 1
    Then you need to tweak the traits of your `type AccountId` in `pallet_system::Config` accordingly, like `type AccountId = From<[u8; 32]>`. I'll try and post more details later. But note that now you are saying that all accountId types need to be 32 bytes, and substrate does not want to make this assumption by default. – kianenigma Apr 06 '21 at 14:00