5

I know that networks can add their SS58 address format to SS58 Registry.

Polkadot addresses always start with 1 and Crust Network addresses start with c.

Does a unique prefix determine how the addresses start? If so, (or not) how can one create an SS58 address format starting with the letter e?

1
  • My guess is trial and error. I had this question long back as well but never found a satisfactory answer. May 1, 2022 at 10:23

1 Answer 1

5

Yes, the unique prefix is used to determine how a SS58 Address starts. It may be generated by this encodeAddress function from the Polkadot.js API. The function shows that the unique SS58 Address Prefix is provided as the ss58Format argument along with the public key, and then uses it to generate and return a base58 encoded string. It shows that SS58 Address Prefixes 46 and 47 are reserved, and there may only be a maximum of 16383 SS58 Address Prefixes.

If you want to create SS58 addresses with a format starting with the letter e, then you could write a script like below that finds all the possible SS58 address prefixes that would do that. If you wanted to choose an SS58 address prefix for your chain that does that, then you would filter out the SS58 address prefixes that have already been assigned to another chain that are listed in the SS58 Registry, since multiple SS58 address prefixes are able to create SS58 address that start with the letter 'e'.

const { encodeAddress } = require("@polkadot/util-crypto");

// Public Key of Alice `subkey inspect //Alice`
const address = "0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d";
const maxSS58AddressPrefixesCount = 16383;

// Find SS58 Address Prefixes that generate an SS58 Address Format that starts with the letter 'e'
// Optionally add a filter to this function if you only want to return those not listed in the
// the SS58 Registry https://github.com/paritytech/ss58-registry/blob/main/ss58-registry.json
function findSS58AddressPrefixes(address) {
  let foundSS58AddressPrefixes = []; 
  let reservedSS58Formats = [46, 47];

  // 
  for (let prefix = 0; prefix <= maxSS58AddressPrefixesCount; prefix++) {
    if (!reservedSS58Formats.includes(prefix)) {
      let ss58Address = encodeAddress(address, prefix);
      console.log(`${prefix}`, ss58Address);
      if (ss58Address.charAt(0) == 'e') {
        foundSS58AddressPrefixes.push(prefix);
      }
    }
  }

  return foundSS58AddressPrefixes;
}

let foundSS58AddressPrefixes = findSS58AddressPrefixes(address);
console.log('count: ', foundSS58AddressPrefixes.length);
console.log('foundSS58AddressPrefixes: ', foundSS58AddressPrefixes);

If you run that script it outputs the following, which shows that there are 581 SS58 Address Prefixes that would create an SS58 Address Format starting with the letter 'e':

count: 581
foundSS58AddressPrefixes: [
    81,   82,   83,   84,   85,   86,   87,   88,   89,  337,
   338,  339,  340,  341,  342,  343,  344,  345,  593,  594,
   595,  596,  597,  598,  599,  600,  601,  848,  849,  850,
   851,  852,  853,  854,  855,  856,  857, 1104, 1105, 1106,
  1107, 1108, 1109, 1110, 1111, 1112, 1113, 1360, 1361, 1362,
  1363, 1364, 1365, 1366, 1367, 1368, 1369, 1616, 1617, 1618,
  1619, 1620, 1621, 1622, 1623, 1624, 1625, 1872, 1873, 1874,
  1875, 1876, 1877, 1878, 1879, 1880, 1881, 2128, 2129, 2130,
  2131, 2132, 2133, 2134, 2135, 2136, 2384, 2385, 2386, 2387,
  2388, 2389, 2390, 2391, 2392, 2640, 2641, 2642, 2643, 2644,
  ... 481 more items
]

Your Answer

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

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