2

I've seen lots of tables on which bytes to use as the prefix for types of addresses. For example 0x00 for legacy addresses starting with a 1. But what's the prefix for native segwit 'bc1q'? I've tried using the base58 table with no success. Thanks

Murch
  • 71,155
  • 33
  • 180
  • 600
Chiru
  • 141
  • 6

1 Answers1

4

Native segwit addresses are not encoded using base58, but using a different encoding system called bech32. The details can be found in BIP 173. For the segwit v1+ addresses that will be used for Taproot, see the amended bech32m encoding in BIP 350.

In short, the addresses consist of:

  • A human readable part, which is bc for Bitcoin mainnet segwit addresses.
  • A separator (1)
  • A payload (storing the actual script data), consisting of:
    • A character for the witness version (q for witness v0, p for witness v1, ...). See the BIPs for details on the character set.
    • A variable number of characters storing the witness program (32 characters for 20-byte witness programs like P2WPKH has; 52 characters for 32-byte witness programs like P2WSH or P2TR have). The 8-bit data is converted to 5-bit groups, and encoded using the bech32 character set.
  • 6 characters checksum, using the checksum algorithm specified in BIP173 or BIP350.
Pieter Wuille
  • 98,249
  • 9
  • 183
  • 287