The range of possible address length

While base64-encoded strings have a constant length depending on the length of data to encode. In base58 it depends on the exact data to encode, e.g. it is shorter if encoded data have more leading zeroes.

Building an aepp you may need to know the range of possible address lengths to validate an user-provided addresses (though better to use isEncoded) or for designs of address-related components. Doing manual tests you may conclude that account address length is between 52 and 53 chars, but it is not correct.

import { AccountMemory } from '@aeternity/aepp-sdk';

const result = new Array(10000)
  .fill()
  .map(() => AccountMemory.generate().address.length)
  .reduce((p, n) => ({ ...p, [n]: (p[n] ?? 0) + 1 }), {});

console.log(result);

Running the above code you would get something like { '51': 55, '52': 5021, '53': 4924 } depending on generated accounts. So, while the most of addresses have length between 52 and 53 chars, there is a ~0.55% chance to get an address of 51 chars.

Theoretically there can be even shorter addresses if they lucky to be prefixed with a long sequence of 0.

import { AccountMemory, Encoding, encode, decode } from '@aeternity/aepp-sdk';

const publicKey = decode(AccountMemory.generate().address);

for (let i = -1; i < publicKey.length; i += 1) {
  if (i >= 0) publicKey[i] = 0;
  const address = encode(publicKey, Encoding.AccountAddress);
  console.log(address.length, address);
}

Running the above code you would get output like

Therefore the minimum address length is 41 chars. All these addresses valid, for exampleak_11111111111111111111111111111111273Yts used to collect AENS name fees.

Last updated

Was this helpful?