Module Prefix in src/lib_crypto/base58.ml has lines such as let ed25519_public_key_hash = "\006\161\159" (* tz1(36) *).

How does one get "\006\161\159" from tz1(36)?

2 Answers 2


Base58 encodes characters by appending a prefix, treating the bytes as a big endian number and writing that big endian number in base 58.

Therefore, specific prefixes can pin down the most significant "digits" in Base58.

The python script b58_prefix.py in the scripts directory of the Tezos repo can help find those prefixes. Note that to run it you will need this version of the python lib pybitcointools

pip install git+https://github.com/vbuterin/pybitcointools.git@aeb0a2bbb8bbfe421432d776c649650eaeb882a5#egg=master
  • How do you convert the byte array "\006\161\159" into a magicbyte value that can be passed to the bitcoin.bin_to_b58check function? I discovered that you can use struct.unpack with the hex values of the byte array like this (generates p2sig(98))P256_SIGNATURE = struct.unpack('>L', b'\x36\xF0\x2C\x34')[0], but "\006\161\159" is only 3 bytes so it can't be packed into a 4-byte big-endian integer. Feb 16, 2019 at 22:02
  • see also the pending MR gitlab.com/tezos/tezos/-/merge_requests/1528 that documents this script further.
    – arvidj
    Apr 8, 2020 at 8:57

Base58 prefixes will always produce a prefixed output for a set length of output. So the input address is 20 bytes + the 3 byte prefix gives a 36 char long address with tz1.

You calculate these prefixes by guess and check.

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.