Search code examples
substrate

How do I convert FRAME's AccountId to network specific SS58?


I want to convert AccountId to SS58 format with a custom network prefix.

Basically replicate the following from JS utilities, e.g.:

Change Address Prefix (Prefix Lookup), Prefix = 50

5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY

65ADzWZUAKXQGZVhQ7ebqRdqEzMEftKytB8a7rknW82EASXB

How to do it generically in a Substrate pallet? Do I need to add an associated type into my configuration trait extending the Ss58Codec trait or can I somehow convert AccountId to AccountId32 and then use its to_ss58check_with_version() function?


Solution

  • In the end I decided against the address being processed in ss58 format in runtime as that it is regarded as strictly external thing. Moreover all functions related to ss58 in substrate use STD so it is not possible to use as-is for wasm compilation.

    The alternative solution was to handle this situation in JS UI where I would explain to user what the pubkey address is and what ss58 address it maps to using this code. Address in signed message would stay in hex format.