15

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?

Paul
  • 361
  • 1
  • 3
  • 11

1 Answers1

14

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.

Pieter Wuille
  • 105,497
  • 9
  • 194
  • 308
  • 2
    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 Aug 09 '17 at 18:46
  • 2
    Yes to all of those. – Pieter Wuille Aug 09 '17 at 18:55
  • 2
    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 Oct 25 '17 at 07:06
  • 1
    Is there perhaps any benefit in using a P2SH address instead of a P2PKH address? – venzen Oct 25 '17 at 07:11
  • Why do you need to do this stupid addwitness to a different address? It does not make any sense. – Giovanni Di Stasi Dec 11 '17 at 15:59
  • 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 Dec 11 '17 at 17:52
  • @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 Dec 11 '17 at 17:55
  • i tried these instructions.

    i have not downloaded the full blockchain.

    I get this error - Segregated witness not enabled on network (code -4)

    – mrtechmaker Dec 26 '17 at 09:53
  • i think - https://github.com/bitcoin/bitcoin/pull/11400 solves above mention error i got. – mrtechmaker Dec 27 '17 at 08:19
  • How does one generate the legacy address back from its corresponding segwit address ? is there a command as below : getlegacyaddress – mrtechmaker Dec 27 '17 at 08:36
  • @Karan That sounds like it could be a separate question. – Pieter Wuille Dec 27 '17 at 08:37
  • 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 Dec 27 '17 at 08:42
  • "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 Apr 03 '18 at 18:12
  • Can I still generate "legacy" address with core 0.16 ? – Haddar Macdasi Apr 03 '18 at 18:19
  • Yes, run with -addresstype=legacy. – Pieter Wuille Apr 03 '18 at 18:22
  • 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 Apr 03 '18 at 18:44