1

I have the following testnet wallet address:

2MsQEtPJ6JJZszMYrD6udjUyTDFLczWQrv9

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

C401B47E5722F808856A308FA043CCF28323F51711E8165536

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

01B47E5722F808856A308FA043CCF28323F51711

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": [
    "mffyC9xbwyBQUWhV8SbYWpqaiNSSWR2vpo"
  ],
  "p2sh": "2ND12E9b9oa9hvTTckXwNaSJiRZ39eRFWSJ"

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

3

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 '18 at 19:22
  • They are not necessarily P2SH. You are probably confusing them with something else. – Andrew Chow Apr 23 '18 at 20:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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