How can I get SS58 address from Account ID?

Viewed 653

How can I get SS58 address from Account ID? Account ID: 0x6d6f646c63622f62726964670000000000000000000000000000000000000000 ss58 address: ?

2 Answers

https://github.com/paritytech/substrate/wiki/External-Address-Format-(SS58)

You can use the JS library to do this simply: https://substrate.dev/docs/en/knowledgebase/advanced/ss58-address-format#polkadotjs

Here is a set of tools that use this library: https://www.shawntabrizi.com/substrate-js-utilities/

// Import Polkadot.js API dependencies.
const { decodeAddress, encodeAddress } = require("@polkadot/keyring");
const { hexToU8a, isHex } = require("@polkadot/util");

// Specify an address to test.
const address = "<addressToTest>";

// Check address.
const isValidSubstrateAddress = () => {
  try {
    encodeAddress(isHex(address) ? hexToU8a(address) : decodeAddress(address));

    return true;
  } catch (error) {
    return false;
  }
};

// Query result.
const isValid = isValidSubstrateAddress();
console.log(isValid);

Also, you may use the SS58 online address converter: https://ss58.org

For example, when using the Substrate network prefix (42) your account ID will produce the following address:

5EYCAe5g7bGpFHagwe26HiRHdHdE3hobrwV6hq1UD2BPAiZb
Related