I'm using private libbitcoin server and libbitcoin explorer. When I use bx fetxh-transaction, it returns something like:

enter image description here

I'm trying to figure out, how to get right address from address_hash. When I use bx base58check-encode for input address_hash without version (or -v 0) it returns:

enter image description here

When I use bx base58check-encode -v 5 it returns:

enter image description here

Check by blockexplorer shows the second way is right. My question is: How to determine base58check-encode version to generate right address?

Thank you.


Your address 32feVAD9Haq1CtfT6JCLTt4L5qef3UnVpY is a P2SH mainnet address, with a 05 address prefix and represents the base58 encoding of the following data:

  • [05][20-byte hash][4-byte checksum]

So, the [05] prefix tells your wallet that your address represents a P2SH embedded script presage (20B).

On the other hand, a [00] prefix tells your wallet that the 20B digest represents a Public-Key-Hash, and that funds should be sent to a P2PKH (Pay-2-Public-Key-Hash) output.

The version number therefore gives your wallet the necessary information to produce the correct output type when sending funds, so that the recipient has the private keys (P2PKH) or presage (P2SH) to spend them.

The 05 prefix translates to a 3 in base58 encoding, which is why your addresses begin with 3. I cannot comment on what the embedded script type is though, since the P2SH has is simply the 20B hash-digest thereof. Perhaps a P2SH(P2WPKH) script type.

Amended Answer:

To determine the address version appropriate for a specific output from a transaction, simply look at the output script in question.

  • P2PKH: "hash160 [20B] equal" -> version 5
  • P2SH: "dup hash160 [20B] equalverify checksig" -> version 0
  • P2WPKH: "[00] [20B]" -> bech32 address
  • Thank you for response. Bx explorer returns address_hash as shown above, but my problem is how to correct determine version from bx response. Other blockexplorers like blockchain.info or bitpay insight shows right address, so there is a way to determine the right version. Miss I anything? – Ramirez Jan 14 at 9:47
  • You mean how to decode the version from an address, such as 32feVAD9Haq1CtfT6JCLTt4L5qef3UnVpY? Try bx address-decode 32feVAD9Haq1CtfT6JCLTt4L5qef3UnVpY – James C. Jan 14 at 9:50
  • No. I want to use bx fetch-tx result to generate address. It returns address_hash and bx base58check-encode returns address. But only with right version choosen it leads to the right address. My problem is to determine the right version. – Ramirez Jan 14 at 9:55
  • I see. You have to examine the output scripts when you fetch the tx. The output script pattern (P2SH or P2PKH etc.) will tell you what version is required (05 or 00 etc.). BX doesn't recognise script patterns for you. Libbitcoin-System has internal methods which check for standard output script patterns, if you want to look into the Libbitcoin C++ library. – James C. Jan 14 at 10:12
  • If this answer helped u, your up/downvote/check would be appreciated either way. Thank you. – James C. Jan 14 at 19:05

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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