0

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?

2
  • 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. Commented Dec 13, 2023 at 12:25
  • thanks, I think so too, but not very sure
    – Jack Green
    Commented Dec 13, 2023 at 13:18

1 Answer 1

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, while the softfork that gave meaning to this script is in BIP16.
  • P2WPKH addresses (42-character bc1q...): 22-byte hex 0014..., encoding script OP_0 <...>. The address format is in BIP173 while the softfork is in BIP141.
  • 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 and the softfork is in BIP341.

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).

3
  • thanks for your answer
    – Jack Green
    Commented Dec 13, 2023 at 13:40
  • 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
    Commented Dec 13, 2023 at 13:48
  • Now I understand completely
    – Jack Green
    Commented Dec 13, 2023 at 13:57

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.