<p>Bitcoin addresses are standardized human-readable notations for certain classes of specific scriptPubKeys. While there is nothing invalid about scripts outside of these standard forms, there is generally very little reason to, and it is uncommon. These forms (as of december 2023) are:</p>
<ul>
<li>P2PKH addresses (1...): 25-byte hex <code>76a914...88ac</code>, encoding script <code>OP_DUP OP_HASH160 &lt;...&gt; OP_EQUALVERIFY OP_CHECKSIG</code>, present since the first Bitcoin software release.</li>
<li>P2SH addresses (3...): 23-byte hex <code>a914...87</code>, encoding script <code>OP_HASH160 &lt;...&gt; OP_EQUAL</code>. The address format is defined in <a href="https://github.com/bitcoin/bips/blob/master/bip-0013.mediawiki" rel="nofollow noreferrer">BIP13</a>, while the softfork that gave meaning to this script is in <a href="https://github.com/bitcoin/bips/blob/master/bip-0016.mediawiki" rel="nofollow noreferrer">BIP16</a>.</li>
<li>P2WPKH addresses (42-character bc1q...): 22-byte hex <code>0014...</code>, encoding script <code>OP_0 &lt;...&gt;</code>. The address format is in <a href="https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki" rel="nofollow noreferrer">BIP173</a> while the softfork is in <a href="https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki" rel="nofollow noreferrer">BIP141</a>.</li>
<li>P2WSH addresses (62-character bc1q...): 34-byte hex <code>0020...</code>, encoding script <code>OP_0 &lt;...&gt;</code>. Like P2WPKH, the relevant bips are BIP173 and BIP141.</li>
<li>P2TR addresses (62-character bc1p...): 34-byte hex <code>5120...</code>, encoding script <code>OP_1 &lt;...&gt;</code>. The address format is defined in <a href="https://github.com/bitcoin/bips/blob/master/bip-0350.mediawiki" rel="nofollow noreferrer">BIP350</a> and the softfork is in <a href="https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki" rel="nofollow noreferrer">BIP341</a>.</li>
</ul>
<p>The address you gave above is a P2WPKH address (its prefix and length don't exactly match the table above due to it being for regtest), and the hexadecimal scriptPubKey is the correct corresponding script. If you add more opcodes, it won't match the address anymore (and almost certainly not do what you want).</p>

CC BY-SA 4.0
2023-12-13T13:40:31.587Z
thanks for your answer
Jack Green
CC BY-SA 4.0
2023-12-13T13:48:51.547Z
I have one more question. I set up two vouts in coinbase. The first vout stores the reward and scriptpubkey for miners. The second vout stores the defalult_witness_commitment. This value comes from the "getblocktemplate" command. Is this setting correct? like this: vout1=reward+size(scriptpubkey)+scriptpubkey    vout2=0+size(defalult_witness_commitment)+defalult_witness_commitment
Jack Green
CC BY-SA 4.0
2023-12-13T13:57:32.137Z
Now I understand completely
Jack Green
CC BY-SA 4.0
2023-12-13T13:34:00.547Z
2023-12-13T13:41:32.697Z
2023-12-13T13:41:32.697Z
Pieter Wuille
<p>I found that the &quot;getaddressinfo&quot; command in RPC can get pubkey and scriptpubkey. My address pubkey scriptpubkey are:</p>
<pre><code>address='bcrt1q95h0le6kknpnjp4c29cau03gvdyxd35zug30yr'
pubKey='022847e92a4202b75e5799ed13d1a529dcfcafc5d594bdf1e2c2a14f462683aeb8'
scriptPubKey='00142d2effe756b4c33906b85171de3e28634866c682'
</code></pre>
<p>I tried to put the scriptpubkey into output script of coinbase transaction, and it correctly generated new blocks. And the block also shows the correct address. But that's without adding any opcodes. If I add opcode, it can generate a new block, but the block shows the wrong address, or no address. So should I add opcodes or not? If should, what opcodes?</p>

CC BY-SA 4.0
2023-12-13T12:25:27.780Z
The scriptPubKey (as you give in hex above) already contains all the opcodes it needs. If you add more, it won't be the same script, and it generally won't have a corresponding address. There is no reason to do that, though it is legal.
Pieter Wuille
CC BY-SA 4.0
2023-12-13T13:18:08.523Z
thanks, I think so too, but not very sure
Jack Green
<script><public-key><coinbase-transaction><output-script>
How to set the output script of coinbase transaction
Jack Green
# How to set the output script of coinbase transaction

(Asked by: username_0 on 2023-12-13)

I found that the "getaddressinfo" command in RPC can get pubkey and scriptpubkey. My address pubkey scriptpubkey are:

```
address='bcrt1q95h0le6kknpnjp4c29cau03gvdyxd35zug30yr'
pubKey='022847e92a4202b75e5799ed13d1a529dcfcafc5d594bdf1e2c2a14f462683aeb8'
scriptPubKey='00142d2effe756b4c33906b85171de3e28634866c682'

```

I tried to put the scriptpubkey into output script of coinbase transaction, and it correctly generated new blocks. And the block also shows the correct address. But that's without adding any opcodes. If I add opcode, it can generate a new block, but the block shows the wrong address, or no address. So should I add opcodes or not? If should, what opcodes?

**Tags:** script, public-key, coinbase-transaction, output-script

> **Comments:**
> **username_1**: The scriptPubKey (as you give in hex above) already contains all the opcodes it needs. If you add more, it won't be the same script, and it generally won't have a corresponding address. There is no reason to do that, though it is legal.  
> **username_0**: thanks, I think so too, but not very sure  

---

## 1 answers

### Answer by username_1 on 2023-12-13. Score: 1

Bitcoin addresses are standardized human-readable notations for certain classes of specific scriptPubKeys. While there is nothing invalid about scripts outside of these standard forms, there is generally very little reason to, and it is uncommon. These forms (as of december 2023) are:

* P2PKH addresses (1...): 25-byte hex `76a914...88ac`, encoding script `OP_DUP OP_HASH160 <...> OP_EQUALVERIFY OP_CHECKSIG`, present since the first Bitcoin software release.
* P2SH addresses (3...): 23-byte hex `a914...87`, encoding script `OP_HASH160 <...> OP_EQUAL`. The address format is defined in [BIP13](https://github.com/bitcoin/bips/blob/master/bip-0013.mediawiki), while the softfork that gave meaning to this script is in [BIP16](https://github.com/bitcoin/bips/blob/master/bip-0016.mediawiki).
* P2WPKH addresses (42-character bc1q...): 22-byte hex `0014...`, encoding script `OP_0 <...>`. The address format is in [BIP173](https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki) while the softfork is in [BIP141](https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki).
* P2WSH addresses (62-character bc1q...): 34-byte hex `0020...`, encoding script `OP_0 <...>`. Like P2WPKH, the relevant bips are BIP173 and BIP141.
* P2TR addresses (62-character bc1p...): 34-byte hex `5120...`, encoding script `OP_1 <...>`. The address format is defined in [BIP350](https://github.com/bitcoin/bips/blob/master/bip-0350.mediawiki) and the softfork is in [BIP341](https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki).

The address you gave above is a P2WPKH address (its prefix and length don't exactly match the table above due to it being for regtest), and the hexadecimal scriptPubKey is the correct corresponding script. If you add more opcodes, it won't match the address anymore (and almost certainly not do what you want).

> **Comments:**
> **username_0**: thanks for your answer  
> **username_0**: I have one more question. I set up two vouts in coinbase. The first vout stores the reward and scriptpubkey for miners. The second vout stores the defalult_witness_commitment. This value comes from the "getblocktemplate" command. Is this setting correct? like this: vout1=reward+size(scriptpubkey)+scriptpubkey    vout2=0+size(defalult_witness_commitment)+defalult_witness_commitment  
> **username_0**: Now I understand completely  

---

