<blockquote>
  <p>How do I generate a SegWit address using Bitcoin Core CLI?</p>
</blockquote>

<p>You can use <code>addwitnessaddress addr</code>, where addr is an existing P2PKH or P2SH address of yours. It will construct a P2SH-P2WPKH or P2SH-P2WSH address with the same key/script, if known to be valid.</p>

<p>Note that this command is not available until SegWit is active on the network, as before that time, such outputs would be spendable by everyone.</p>

<p>Since Bitcoin Core v0.16.0, P2SH-P2WPKH addresses are the default, and the <code>addwitnessaddress</code> RPC is deprecated.</p>

<blockquote>
  <p>Also will I be able to redeem those outputs and send them to a "legacy" address?</p>
</blockquote>

<p>Yes.</p>

<blockquote>
  <p>If so, will this second transaction be accepted by older, non-SegWit clients?</p>
</blockquote>

<p>Yes, it is a softfork. Every new transaction is valid according to the old rule. If not, a chain split would occur. Older clients may not see the transaction until it is confirmed, however.</p>

CC BY-SA 3.0
2017-08-09T18:46:53.960Z
That means I need to generate a "legacy" address and then pass it to addwitnessaddress and it will return a "segwit" address? And I will be able to send the bitcoins received in that "segwit" address to any other address and older clients will not complain (they will "receive" those bitcoins)?
Paul
CC BY-SA 3.0
2017-08-09T18:55:20.593Z
Yes to all of those.
Pieter Wuille
CC BY-SA 3.0
2017-10-25T07:06:50.967Z
in case anyone is interested: the legacy address used to create the SegWit address and the resulting witness address share the same private key.
venzen
CC BY-SA 3.0
2017-10-25T07:11:01.447Z
Is there perhaps any benefit in using a P2SH address instead of a P2PKH address?
venzen
CC BY-SA 3.0
2017-12-11T15:59:21.213Z
Why do you need to do this stupid addwitness to a different address? It does not make any sense.
Giovanni Di Stasi
CC BY-SA 3.0
2017-12-26T09:53:25.560Z
i tried these instructions.

i have not downloaded the full blockchain.

I get this error - Segregated witness not enabled on network (code -4)
mrtechmaker
CC BY-SA 3.0
2017-12-27T08:19:37.900Z
i think - https://github.com/bitcoin/bitcoin/pull/11400
solves above mention error i got.
mrtechmaker
CC BY-SA 3.0
2017-12-27T08:36:03.783Z
How does one generate the legacy address back from its corresponding segwit address ?
is there a command as below :
getlegacyaddress <segwit addr>
mrtechmaker
CC BY-SA 3.0
2017-12-27T08:37:31.007Z
@Karan That sounds like it could be a separate question.
Pieter Wuille
CC BY-SA 3.0
2017-12-27T08:42:34.060Z
sure @PieterWuille.
I added a comment here - https://bitcoin.stackexchange.com/questions/63472/how-to-get-legacy-address-and-private-key-from-segwit-p2sh-address
mrtechmaker
CC BY-SA 3.0
2017-12-11T17:52:37.850Z
It mimicks addmultisigaddress, and teaches the wallet to look for a particular address and how to spend. The initial SegWit implementation only had a rudimentary wallet support sufficient for testing, but we didn't want to do all implementation work if SegWit wouldn't have activated. It has now, so the next Bitcoin Core release will make SegWit addresses default (removing the need for an RPC call, and have better backup recovery).
Pieter Wuille
CC BY-SA 3.0
2017-12-11T17:55:43.317Z
@venzen You'd give a P2SH address if you wanted a SegWit address for a multisig spending condition, as those can't be expressed using P2PKH.
Pieter Wuille
CC BY-SA 3.0
2018-04-03T18:12:49.937Z
"addwitnessaddress is deprecated and will be fully removed in v0.17. To use addwitnessaddress in v0.16, restart bitcoind with -deprecatedrpc=addwitnessaddress.
Projects should transition to using the address_type argument of getnewaddress, or option -addresstype=[bech32|p2sh-segwit] instead.
 (code -32)" from bitcoin core 0.16
Haddar Macdasi
CC BY-SA 3.0
2018-04-03T18:19:09.140Z
Can I still generate "legacy" address with core 0.16 ?
Haddar Macdasi
CC BY-SA 3.0
2018-04-03T18:22:10.183Z
Yes, run with `-addresstype=legacy`.
Pieter Wuille
CC BY-SA 3.0
2018-04-03T18:44:46.993Z
I've opened a new Q concerning V0.16 legacy support
https://bitcoin.stackexchange.com/questions/73411/how-to-add-support-for-segwit-address-and-legacy-with-bitcoin-core-0-16
Haddar Macdasi
CC BY-SA 3.0
2017-08-09T16:22:48.533Z
2018-04-03T18:14:04.253Z
2018-04-03T18:14:04.253Z
Pieter Wuille
<p>How do I generate a SegWit address using Bitcoin Core CLI? Also will I be able to redeem those outputs and send them to a "legacy" address? If so, will this second transaction be accepted by older, non-SegWit clients?</p>

CC BY-SA 3.0
2017-08-09T14:34:04.990Z
It's intended not to be easy for users to create P2WPKH addresses until it's live on the network.
m1xolyd1an
CC BY-SA 3.0
2017-08-09T18:48:10.033Z
It doesn't seem to be complicated as per the response below.
Paul
<bitcoin-core><bitcoind><json-rpc><segregated-witness><bitcoin-cli>
How to generate SegWit address
Paul
# How to generate SegWit address

(Asked by: username_0 on 2017-08-09)

How do I generate a SegWit address using Bitcoin Core CLI? Also will I be able to redeem those outputs and send them to a "legacy" address? If so, will this second transaction be accepted by older, non-SegWit clients?

**Tags:** bitcoin-core, bitcoind, json-rpc, segregated-witness, bitcoin-cli

> **Comments:**
> **username_1**: It's intended not to be easy for users to create P2WPKH addresses until it's live on the network.  
> **username_0**: It doesn't seem to be complicated as per the response below.  

---

## 1 answers

### Answer by username_2 on 2017-08-09. Score: 14 | Accepted answer

> How do I generate a SegWit address using Bitcoin Core CLI?

You can use `addwitnessaddress addr`, where addr is an existing P2PKH or P2SH address of yours. It will construct a P2SH-P2WPKH or P2SH-P2WSH address with the same key/script, if known to be valid.

Note that this command is not available until SegWit is active on the network, as before that time, such outputs would be spendable by everyone.

Since Bitcoin Core v0.16.0, P2SH-P2WPKH addresses are the default, and the `addwitnessaddress` RPC is deprecated.

> Also will I be able to redeem those outputs and send them to a "legacy" address?

Yes.

> If so, will this second transaction be accepted by older, non-SegWit clients?

Yes, it is a softfork. Every new transaction is valid according to the old rule. If not, a chain split would occur. Older clients may not see the transaction until it is confirmed, however.

> **Comments:**
> **username_0**: That means I need to generate a "legacy" address and then pass it to addwitnessaddress and it will return a "segwit" address? And I will be able to send the bitcoins received in that "segwit" address to any other address and older clients will not complain (they will "receive" those bitcoins)?  
> **username_2**: Yes to all of those.  
> **username_3**: in case anyone is interested: the legacy address used to create the SegWit address and the resulting witness address share the same private key.  
> **username_3**: Is there perhaps any benefit in using a P2SH address instead of a P2PKH address?  
> **username_4**: Why do you need to do this stupid addwitness to a different address? It does not make any sense.  
> **username_2**: It mimicks addmultisigaddress, and teaches the wallet to look for a particular address and how to spend. The initial SegWit implementation only had a rudimentary wallet support sufficient for testing, but we didn't want to do all implementation work if SegWit wouldn't have activated. It has now, so the next Bitcoin Core release will make SegWit addresses default (removing the need for an RPC call, and have better backup recovery).  
> **username_2**: @username_3 You'd give a P2SH address if you wanted a SegWit address for a multisig spending condition, as those can't be expressed using P2PKH.  
> **username_5**: i tried these instructions.  i have not downloaded the full blockchain.  I get this error - Segregated witness not enabled on network (code -4)  
> **username_5**: i think - https://github.com/bitcoin/bitcoin/pull/11400 solves above mention error i got.  
> **username_5**: How does one generate the legacy address back from its corresponding segwit address ? is there a command as below : getlegacyaddress <segwit addr>  
> **username_2**: @Karan That sounds like it could be a separate question.  
> **username_5**: sure @username_2. I added a comment here - https://bitcoin.stackexchange.com/questions/63472/how-to-get-legacy-address-and-private-key-from-segwit-p2sh-address  
> **username_6**: "addwitnessaddress is deprecated and will be fully removed in v0.17. To use addwitnessaddress in v0.16, restart bitcoind with -deprecatedrpc=addwitnessaddress. Projects should transition to using the address_type argument of getnewaddress, or option -addresstype=[bech32|p2sh-segwit] instead.  (code -32)" from bitcoin core 0.16  
> **username_6**: Can I still generate "legacy" address with core 0.16 ?  
> **username_2**: Yes, run with `-addresstype=legacy`.  
> **username_6**: I've opened a new Q concerning V0.16 legacy support https://bitcoin.stackexchange.com/questions/73411/how-to-add-support-for-segwit-address-and-legacy-with-bitcoin-core-0-16  

---

