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

<p>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 </p>

<pre><code>OP_HASH160 01b47e5722f808856a308fa043ccf28323f51711 OP_EQUAL
</code></pre>

CC BY-SA 3.0
2018-04-23T19:22:21.347Z
Thanks!, so if the version byte is "0xc4" then I can tell it's a P2SH address...I now I get https://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
CC BY-SA 3.0
2018-04-23T20:07:42.867Z
They are not necessarily P2SH. You are probably confusing them with something else.
Ava Chow
CC BY-SA 3.0
2018-04-23T18:24:41.847Z
2018-04-23T18:24:41.847Z
Ava Chow
<p>I have the following testnet wallet address:</p>

<pre><code>2MsQEtPJ6JJZszMYrD6udjUyTDFLczWQrv9
</code></pre>

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

<pre><code>C401B47E5722F808856A308FA043CCF28323F51711E8165536
</code></pre>

<p>I strip it off the version byte prefix and the checksum postfix, and I get:</p>

<pre><code>01B47E5722F808856A308FA043CCF28323F51711
</code></pre>

<p>So the scriptPubKey should be </p>

<pre><code>76a91401b47e5722f808856a308fa043ccf28323f5171188ac which is OP_DUP OP_HASH160 01b47e5722f808856a308fa043ccf28323f51711 OP_EQUALVERIFY OP_CHECKSIG
</code></pre>

<p>But as a sanity unit test, i verify it Vs. the debug console </p>

<pre><code>decodescript 76a91401b47e5722f808856a308fa043ccf28323f5171188ac
</code></pre>

<p>But the debug console gives me this:</p>

<pre><code>  "asm": "OP_DUP OP_HASH160 01b47e5722f808856a308fa043ccf28323f51711 OP_EQUALVERIFY OP_CHECKSIG",
  "reqSigs": 1,
  "type": "pubkeyhash",
  "addresses": [
    "mffyC9xbwyBQUWhV8SbYWpqaiNSSWR2vpo"
  ],
  "p2sh": "2ND12E9b9oa9hvTTckXwNaSJiRZ39eRFWSJ"
</code></pre>

<p>So why do I get address "mffyC9xbwyBQUWhV8SbYWpqaiNSSWR2vpo" and not "2MsQEtPJ6JJZszMYrD6udjUyTDFLczWQrv9" as I expect?</p>

<transactions><bitcoind><testnet><coinbase-transaction>
Fail to encrypt scriptPubKey in testnet
dodo
# Fail to encrypt scriptPubKey in testnet

(Asked by: username_0 on 2018-04-23)

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?

**Tags:** transactions, bitcoind, testnet, coinbase-transaction


---

## 1 answers

### Answer by username_1 on 2018-04-23. Score: 3 | Accepted answer

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

```

> **Comments:**
> **username_0**: Thanks!, so if the version byte is "0xc4" then I can tell it's a P2SH address...I now I get https://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  
> **username_1**: They are not necessarily P2SH. You are probably confusing them with something else.  

---

