<p>P2SH-P2WPKH addresses can only be created by segwit-compatible wallet software. However, sending <em>to</em> a P2SH-P2WPKH works with any P2SH-compatible wallet, as the address is indistinguishable from (and effectively <em>is</em>) a P2SH address.</p>
<p>It was useful in a time before most wallets supported segwit, as even those that did not usually supported P2SH.</p>

CC BY-SA 4.0
2023-09-03T19:27:37.917Z
So there is no need (real purpose) anymore for P2SH-P2WPKH? Btw is it correct to say `P2SH-P2WPKH` or `P2WPKH-P2SH` for P2WPKH nested in P2SH?
dassd
CC BY-SA 4.0
2023-09-03T19:32:59.190Z
You can say what you want, but I think P2SH-P2WPKH is a lot more common. Most (but still not all) wallets support BIP173 (native segwit v0 addresses) now, so it is certainly less useful than a few years ago.
Pieter Wuille
CC BY-SA 4.0
2023-09-03T19:35:51.820Z
Okay, but what do you mean by saying "P2SH-P2WPKH addresses can only be created by segwit-compatible wallet software."? I do not get this. If that is a P2SH then it will follow classic P2SH scheme and address will start with `3`, it won't even know if the hash is from some random redeem script or from witness program (0 for version then 20 byte for hash of public key)? How does wallet wont be able to create address when its literally classic P2SH?
dassd
CC BY-SA 4.0
2023-09-03T19:37:37.780Z
By "creating" an address I mean generating a private key, computing the corresponding script, and converting it to an address, so it can be given out to senders, while being able to spend the coins sent to that address. While it's true that software can compute a P2SH address for any P2SH script, that's not the same as a receiving wallet creating such an address to actually use it.
Pieter Wuille
CC BY-SA 4.0
2023-09-03T19:47:50.940Z
Okay, but if P2SH-P2WPKH can only be created by segwit compatible wallet, how will that help, that is how will that change anything? I do not get it. If you send P2SH-P2WPKH to non-segwit wallet then that wallet can't spend it because it does not know to work with segwit? Is the point that the user will know in this way that funds have been sent to him because it is P2SH (P2WPKH nested), but he will not be able to spend them because his wallet is not segwit compatible? Otherwise, if it is only P2WPKH he wouldn't even be able to see that the funds arrived? In this way he can at least see that.
dassd
CC BY-SA 4.0
2023-09-03T19:55:55.930Z
I think you're confusing sender and receiver. The receiver creates the address, and they only create addresses they know how to spend from. So P2SH-P2WPKH can be used by receivers who support segwit, but with senders that only support P2SH (but do not know about segwit, as they don't care). When the funds arrive at the receiver, and they want to send those funds onward, they need a segwit spend, but they know how to construct that, as they are a segwit wallet.
Pieter Wuille
CC BY-SA 4.0
2023-09-03T20:12:03.403Z
"If you send P2SH-P2WPKH to non-segwit wallet then that wallet can't spend it because it does not know to work with segwit?" - This cannot happen, because the non-segwit wallet will not give out a P2WPKH address; it'll give a P2PKH address for example, which it does know how to spend.
Pieter Wuille
CC BY-SA 4.0
2023-09-03T21:14:54.583Z
So, if I (my wallet) know how to work with SegWit (as a result of wanting to work with unconfirmed transactions, to avoid malleability, lower fee, etc.) I can actually generate P2SH address that will contain hash of P2WPKH (0 20byte-hash) instead of some random redeem script as in "traditional" P2SH, and give it to some sender that does not need to understand the P2WPKH. In this way, he will "pay" to classic P2SH (cause he does not know how to create P2WPKH locking script, just P2SH locking script) and I can get all the benefit from working with P2WPKH (which is actually "packed" in P2SH)?
dassd
CC BY-SA 4.0
2023-09-03T21:17:29.810Z
@maximus Exactly. You get the benefits of segwit (with a small penalty, the P2SH wrapping has a cost), but you get to receive coins from senders who do not support native segwit addresses.
Pieter Wuille
CC BY-SA 4.0
2023-09-03T21:18:25.093Z
What kind of cost?
dassd
CC BY-SA 4.0
2023-09-03T21:24:57.077Z
The P2SH wrapper increases the size of transaction inputs that spend outputs sending to P2SH-P2WPKH, compared to spending P2WPKH outputs. As transaction fees generally scale with the size (weight) of the transaction, the wrapper increases the fees for the receiver.
Pieter Wuille
CC BY-SA 4.0
2023-09-03T21:27:42.063Z
So with P2SH-P2WPKH you have to pay bigger fee than for classic P2WPKH but at least you will get the other benefits that P2WPKH provides (for example resistance to malleability) comparing to "traditional" P2PKH?
dassd
CC BY-SA 4.0
2023-09-03T21:31:03.330Z
Yes, but P2SH-P2WPKH is also cheaper (=smaller input) than P2PKH, just not quite as cheap as native P2WPKH. P2TR key path spends are even cheaper.
Pieter Wuille
CC BY-SA 4.0
2023-09-03T21:50:06.930Z
So in context of fee (from the biggest to lowest fee): P2SH/P2PKH -> P2SH-P2WPKH/P2SH-P2WSH -> P2WPKH/P2WSH -> P2TR. Additionally, SegWit (v0 - P2WSH/P2WPKH, v1 - P2TR) has other benefits, with the fact that v1 (P2TR) has provides even greater benefits compared to v0 (P2WSH/P2WPKH)?
dassd
CC BY-SA 4.0
2023-09-03T22:11:14.387Z
In general yes. It's more complicated for the script variants (P2SH, P2WSH, P2TR script path), as the cost of spending is also a function of the complexity of the script/spending policy involved. There are several answers on this site with comparisons of script type costs, though.
Pieter Wuille
CC BY-SA 4.0
2023-09-03T22:19:19.953Z
Can you give me a link to some such posts that compare it in detail? Maybe some that you wrote? It would be help a lot.
dassd
CC BY-SA 4.0
2023-09-04T09:28:43.327Z
@maximus https://bitcoin.stackexchange.com/a/84006/140802
dassd
CC BY-SA 4.0
2023-09-03T19:24:34.883Z
2023-09-03T19:24:34.883Z
Pieter Wuille
<p>When I ask the google what is the purpose of P2WPKH nested in P2SH, it says the following:</p>
<blockquote>
<p>This allows the user to send funds to a SegWit (Segregated Witness)
address using a non-SegWit transaction, which can be useful in cases
where the user's wallet or software does not support SegWit
transactions.</p>
</blockquote>
<p>But I do not get it, if a wallet does not support segwit, how will a wallet then create a transaction with witness data to spends it.</p>
<p>So my question: What is the purpose of P2WPKH-P2SH? What do we get with sending SegWit type to non-segwit address (starting with <code>3</code> base58check for P2SH)?</p>

<segregated-witness><p2sh><p2sh-p2wpkh>
What is the purpose of P2WPKH-P2SH?
dassd
# What is the purpose of P2WPKH-P2SH?

(Asked by: username_0 on 2023-09-03)

When I ask the google what is the purpose of P2WPKH nested in P2SH, it says the following:

> This allows the user to send funds to a SegWit (Segregated Witness)
> address using a non-SegWit transaction, which can be useful in cases
> where the user's wallet or software does not support SegWit
> transactions.

But I do not get it, if a wallet does not support segwit, how will a wallet then create a transaction with witness data to spends it.

So my question: What is the purpose of P2WPKH-P2SH? What do we get with sending SegWit type to non-segwit address (starting with `3` base58check for P2SH)?

**Tags:** segregated-witness, p2sh, p2sh-p2wpkh


---

## 1 answers

### Answer by username_1 on 2023-09-03. Score: 7

P2SH-P2WPKH addresses can only be created by segwit-compatible wallet software. However, sending *to* a P2SH-P2WPKH works with any P2SH-compatible wallet, as the address is indistinguishable from (and effectively *is*) a P2SH address.

It was useful in a time before most wallets supported segwit, as even those that did not usually supported P2SH.

> **Comments:**
> **username_0**: So there is no need (real purpose) anymore for P2SH-P2WPKH? Btw is it correct to say `P2SH-P2WPKH` or `P2WPKH-P2SH` for P2WPKH nested in P2SH?  
> **username_1**: You can say what you want, but I think P2SH-P2WPKH is a lot more common. Most (but still not all) wallets support BIP173 (native segwit v0 addresses) now, so it is certainly less useful than a few years ago.  
> **username_0**: Okay, but what do you mean by saying "P2SH-P2WPKH addresses can only be created by segwit-compatible wallet software."? I do not get this. If that is a P2SH then it will follow classic P2SH scheme and address will start with `3`, it won't even know if the hash is from some random redeem script or from witness program (0 for version then 20 byte for hash of public key)? How does wallet wont be able to create address when its literally classic P2SH?  
> **username_1**: By "creating" an address I mean generating a private key, computing the corresponding script, and converting it to an address, so it can be given out to senders, while being able to spend the coins sent to that address. While it's true that software can compute a P2SH address for any P2SH script, that's not the same as a receiving wallet creating such an address to actually use it.  
> **username_0**: Okay, but if P2SH-P2WPKH can only be created by segwit compatible wallet, how will that help, that is how will that change anything? I do not get it. If you send P2SH-P2WPKH to non-segwit wallet then that wallet can't spend it because it does not know to work with segwit? Is the point that the user will know in this way that funds have been sent to him because it is P2SH (P2WPKH nested), but he will not be able to spend them because his wallet is not segwit compatible? Otherwise, if it is only P2WPKH he wouldn't even be able to see that the funds arrived? In this way he can at least see that.  
> **username_1**: I think you're confusing sender and receiver. The receiver creates the address, and they only create addresses they know how to spend from. So P2SH-P2WPKH can be used by receivers who support segwit, but with senders that only support P2SH (but do not know about segwit, as they don't care). When the funds arrive at the receiver, and they want to send those funds onward, they need a segwit spend, but they know how to construct that, as they are a segwit wallet.  
> **username_1**: "If you send P2SH-P2WPKH to non-segwit wallet then that wallet can't spend it because it does not know to work with segwit?" - This cannot happen, because the non-segwit wallet will not give out a P2WPKH address; it'll give a P2PKH address for example, which it does know how to spend.  
> **username_0**: So, if I (my wallet) know how to work with SegWit (as a result of wanting to work with unconfirmed transactions, to avoid malleability, lower fee, etc.) I can actually generate P2SH address that will contain hash of P2WPKH (0 20byte-hash) instead of some random redeem script as in "traditional" P2SH, and give it to some sender that does not need to understand the P2WPKH. In this way, he will "pay" to classic P2SH (cause he does not know how to create P2WPKH locking script, just P2SH locking script) and I can get all the benefit from working with P2WPKH (which is actually "packed" in P2SH)?  
> **username_1**: @maximus Exactly. You get the benefits of segwit (with a small penalty, the P2SH wrapping has a cost), but you get to receive coins from senders who do not support native segwit addresses.  
> **username_0**: What kind of cost?  
> **username_1**: The P2SH wrapper increases the size of transaction inputs that spend outputs sending to P2SH-P2WPKH, compared to spending P2WPKH outputs. As transaction fees generally scale with the size (weight) of the transaction, the wrapper increases the fees for the receiver.  
> **username_0**: So with P2SH-P2WPKH you have to pay bigger fee than for classic P2WPKH but at least you will get the other benefits that P2WPKH provides (for example resistance to malleability) comparing to "traditional" P2PKH?  
> **username_1**: Yes, but P2SH-P2WPKH is also cheaper (=smaller input) than P2PKH, just not quite as cheap as native P2WPKH. P2TR key path spends are even cheaper.  
> **username_0**: So in context of fee (from the biggest to lowest fee): P2SH/P2PKH -> P2SH-P2WPKH/P2SH-P2WSH -> P2WPKH/P2WSH -> P2TR. Additionally, SegWit (v0 - P2WSH/P2WPKH, v1 - P2TR) has other benefits, with the fact that v1 (P2TR) has provides even greater benefits compared to v0 (P2WSH/P2WPKH)?  
> **username_1**: In general yes. It's more complicated for the script variants (P2SH, P2WSH, P2TR script path), as the cost of spending is also a function of the complexity of the script/spending policy involved. There are several answers on this site with comparisons of script type costs, though.  
> **username_0**: Can you give me a link to some such posts that compare it in detail? Maybe some that you wrote? It would be help a lot.  
> **username_0**: @maximus https://bitcoin.stackexchange.com/a/84006/140802  

---

