3

I have a little bit confusion about addresses segwit and not segwit.

I can see P2WPKH and P2WSH from this link https://en.bitcoin.it/wiki/BIP_0173, and they are segwit and start with bc (mainnet) or tb (testnet).

But I can see even P2SH, start with 3 nested P2WPKH or P2WSH, and that address start with 3.

Then When we speak about P2WPKH and P2WSH we mean Native and start with bc, or We can have even P2WPKH start with 1 and P2WSH start with 3?

when I create

bitcoin-cli getnewaddress "segwit" "p2sh-segwit" 

which kind of script I have? P2PK?

monkeyUser
  • 960
  • 1
  • 7
  • 18
  • 2
    For more information about address types, see [my github writeup](https://github.com/EAWF/Bitcoin-Merchants-Toolbox/blob/master/Address-Derivation.md) on address derivation. – Septem151 Mar 29 '20 at 21:19

1 Answers1

4

6 types of Bitcoin addresses (in parentheses are the data they keep):

Legacy

  • P2PKH 1... (a public key's hash)
  • P2SH 3... (a script's hash) (defined in BIP16)

SegWit (P2WPKH/P2WSH) nested in P2SH (defined in BIP141)

  • P2SH-P2WPKH 3... (a public key's hash)
  • P2SH-P2WSH 3... (a script's hash)

(these start with three because these addresses are meant to be compatible with existing wallets, who would see those addresses as P2SH wallets)

Native SegWit (P2WPKH/P2WSH) (defined in BIP141 + BIP173)

  • P2WPKH bc1... (a public key's hash)
  • P2WSH bc1... (a script's hash) (but longer than P2WPKH)

which kind of script I have? P2PK?

getnewaddress can't return P2PK because you can either pay directly to a script (which can be P2PK) or a script enclosed in P2SH (or its derivatives P2SH-P2WSH and P2WSH). But that's not very useful.

The documentation says:

Arguments:

  1. "label" (string, optional) The label name for the address to be linked to. If not provided, the default label "" is used. It can also be set to the empty string "" to represent the default label. The label does not need to exist, it will be created if there is no label by the given name.

  2. "address_type" (string, optional) The address type to use. Options are "legacy", "p2sh-segwit", and "bech32". Default is set by -addresstype.

The legacy type means P2PKH, p2sh-segwit means P2SH-P2WPKH and bech32 means P2WPKH.

MCCCS
  • 10,097
  • 5
  • 27
  • 55
  • In P2SH-P2WPKH that I can get with `getnewaddress` P2WPKH has the bech32 logic inside (https://en.bitcoin.it/wiki/BIP_0173)? is it native bech32 but wrapped into P2SH? – monkeyUser Mar 29 '20 at 14:47
  • The goal of SegWit addresses is to move signatures to a register named "witness". Because both P2WPKH and P2SH-P2WPKH do that, both are SegWit addresses. But a native SegWit address is more space efficient than a P2SH-nested address; it saves about twenty bytes ([examples](https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#examples)). And Bech32 is the serialization method to represent native SegWit addresses. So both are SegWit addresses but Bech32 is *more SegWit* as it doesn't aim to be backwards-compatible (so old wallets can't send to it but it can send anywhere) – MCCCS Mar 29 '20 at 14:54
  • So slightly different mechanics. – MCCCS Mar 29 '20 at 14:56
  • thanks again, here https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#examples I can See P2WPKH not inside P2SH. In that case what kind of address I have? With 1 ? – monkeyUser Mar 29 '20 at 15:01
  • 1
    If it doesn't mention P2SH and it's SegWit then it's a native address, represented by Bech32. In mainnet all Bech32 addresses start with `bc1` (unless they change it in the future). – MCCCS Mar 29 '20 at 15:18
  • Then P2SH-P2WPKH, P2SH wrap a native P2WPKH, right? thanks again for your time man – monkeyUser Mar 29 '20 at 15:20
  • No they have different spending ways (different scriptSig and scriptPubKey). Another way to think of it as is that a P2WPKH is not a script (there is no CHECKSIG, etc opcodes recorded in the blockchain) therefore it can't be nested in P2SH therefore P2SH-P2WPKH is a completely different format. You're welcome, feel free to ask if you have more questions. – MCCCS Mar 29 '20 at 15:40
  • how can I create P2WPKH not native? – monkeyUser Mar 29 '20 at 19:21
  • The command you wrote in the question does that – MCCCS Mar 29 '20 at 20:36
  • Than I don't understand the different between P2WPKH and P2WPKH nested in BIP16 P2SH and How create these addresses. If with this command `bitcoin-cli getnewaddress "segwit" "p2sh-segwit" ` I create `P2WPKH` How can I create `P2WPKH nested in BIP16 P2SH`? both address are inside P2SH, then both are nested – monkeyUser Mar 29 '20 at 21:32
  • 1
    `bitcoin-cli getnewaddress "segwit" "p2sh-segwit"` is P2SH-P2WPKH. `bitcoin-cli getnewaddress "segwit" "bech32"` is native P2WPKH. – MCCCS Mar 30 '20 at 08:07