I have the following testnet wallet address:


Which I am trying to encode as pubkeyhash to the coinbase TX in testnet. When i run decode58, I get this


I strip it off the version byte prefix and the checksum postfix, and I get:


So the scriptPubKey should be

76a91401b47e5722f808856a308fa043ccf28323f5171188ac which is OP_DUP OP_HASH160 01b47e5722f808856a308fa043ccf28323f51711 OP_EQUALVERIFY OP_CHECKSIG

But as a sanity unit test, i verify it Vs. the debug console

decodescript 76a91401b47e5722f808856a308fa043ccf28323f5171188ac

But the debug console gives me this:

  "asm": "OP_DUP OP_HASH160 01b47e5722f808856a308fa043ccf28323f51711 OP_EQUALVERIFY OP_CHECKSIG",
  "reqSigs": 1,
  "type": "pubkeyhash",
  "addresses": [
  "p2sh": "2ND12E9b9oa9hvTTckXwNaSJiRZ39eRFWSJ"

So why do I get address "mffyC9xbwyBQUWhV8SbYWpqaiNSSWR2vpo" and not "2MsQEtPJ6JJZszMYrD6udjUyTDFLczWQrv9" as I expect?

1 Answer 1


First of all, scriptPubKeys are not encrypted and what you are doing is not encryption. This is encoding.

The problem is that you are trying to encode a P2SH address as a P2PKH scriptPubKey. P2SH addresses are different from P2PKH addresses and have different opcodes. You can identify them by looking at the version number of the address which you are not doing. The version number actually has a meaning, it is not ignorable. Your scriptPubKey should actually be

OP_HASH160 01b47e5722f808856a308fa043ccf28323f51711 OP_EQUAL
  • Thanks!, so if the version byte is "0xc4" then I can tell it's a P2SH address...I now I get en.bitcoin.it/wiki/Base58Check_encoding. What I now wish to understand is why does the opcode are different in P2SH addresses in coinbase transactions
    – dodo
    Apr 23, 2018 at 19:22
  • They are not necessarily P2SH. You are probably confusing them with something else.
    – Ava Chow
    Apr 23, 2018 at 20:07

Your Answer

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

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