Bitcoin Forum
November 18, 2024, 01:29:27 PM *
News: Check out the artwork 1Dq created to commemorate this forum's 15th anniversary
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: How to transfer/import a segwit (P2SH-P2WPKH) address into Bitcoin Core?  (Read 400 times)
RaviMoll (OP)
Newbie
*
Offline Offline

Activity: 14
Merit: 1


View Profile
January 04, 2018, 04:37:18 PM
 #1

How to transfer/import a segwit (P2SH-P2WPKH) address into Bitcoin Core, so that I can send the coins from Bitcoin Core (the original client)?

I have created Segwit addresses (P2SH-P2WPKH) on another client (Armory) and received funds there, and now I want to "import" those Segwit addresses with the Bitcoin core client, so that I can spend the funds from the Bitcoin core client.  I couldn't find how to do that.

With legacy (P2PKH) addresses ("1-" addresses), I can simply import the private keys into Bitcoin core, and it all works fine.  But if I try to import the private key of a segwit (P2SH-P2WPKH) address into Core (through the console) it gives me a legacy "1" address that doesn't correspond to my segwit address - and which doesn't contain my coins, obviously.

What am I doing wrong here, and how could I do that?

Any help would be much appreciated.
RaviMoll (OP)
Newbie
*
Offline Offline

Activity: 14
Merit: 1


View Profile
January 04, 2018, 05:28:04 PM
 #2

Some more specific information, gathered from another thread where goatpig wrote:

Quote
P2SH-P2WPKH is a standard SW script type described in the BIP, any SegWit compliant wallet is expected to support that script type to claim compliance. What you need to figure out is how to instruct the receiving wallet [the Bitcoin core client] to instantiate the associated address as nested SW.
Source:  https://bitcointalk.org/index.php?topic=2679892.msg27479932#msg27479932

It seems that what I need to do is to have the Bitcoin core client to "instantiate the associated address as nested SW".

How could I do that?
cellard
Legendary
*
Offline Offline

Activity: 1372
Merit: 1252


View Profile
January 04, 2018, 06:29:07 PM
 #3

https://github.com/spesmilo/electrum/issues/3620

Im not sure about this, from what I understand there, there is some sort of issue.

Honestly you shouldn't bother with this until Core 0.16 is released with proper segwit support, better to keep using legacy addresses only in Core until 0.16, at least that is what im doing. And once 0.16 is released, Bech32 addresses (the proper segwit ones that begin with bc1) will be easily manageable through the GUI, or that is what I hope for. Once we have bc1 then we can ignore the ones that begin with 3.

RaviMoll (OP)
Newbie
*
Offline Offline

Activity: 14
Merit: 1


View Profile
January 04, 2018, 06:58:51 PM
 #4

Honestly you shouldn't bother with this until Core 0.16 is released with proper segwit support, better to keep using legacy addresses only in Core until 0.16, at least that is what im doing. And once 0.16 is released, Bech32 addresses (the proper segwit ones that begin with bc1) will be easily manageable through the GUI, or that is what I hope for. Once we have bc1 then we can ignore the ones that begin with 3.

I agree with you, however the issue is that I am already using a segwit (P2SH-P2WPKH) address from another wallet, and I want to import that into Core.

I'm sure there must be a way to do that with Core 0.15.1, I just have to find out how!
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3542
Merit: 6886


Just writing some code


View Profile WWW
January 05, 2018, 01:50:42 AM
 #5

But if I try to import the private key of a segwit (P2SH-P2WPKH) address into Core (through the console) it gives me a legacy "1" address that doesn't correspond to my segwit address
Use addwitnessaddress on the legacy address that is imported. Then rescan the blockchain.

RaviMoll (OP)
Newbie
*
Offline Offline

Activity: 14
Merit: 1


View Profile
January 05, 2018, 02:13:36 AM
 #6

But if I try to import the private key of a segwit (P2SH-P2WPKH) address into Core (through the console) it gives me a legacy "1" address that doesn't correspond to my segwit address
Use addwitnessaddress on the legacy address that is imported. Then rescan the blockchain.

I had tried to do that on the console ("addwitnessaddress [the_legacy_address_that_appeared]", but it gave me the error:

"Public key or redeemscript not known to wallet, or the key is uncompressed (code -4)"

(I did not rescan, as it seemed the addwitnessaddress command wasn't successful.)

There's something I do not know or understand about segwit's functionning, and so I have no clue how to progress forward with that.
What would that mean?
RaviMoll (OP)
Newbie
*
Offline Offline

Activity: 14
Merit: 1


View Profile
January 05, 2018, 02:24:18 AM
 #7

If that may help, this is for a P2SH-P2WPKH private key exported from Armory v0.96.3.99 (0.96.4 RC1).
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3542
Merit: 6886


Just writing some code


View Profile WWW
January 05, 2018, 02:26:56 AM
 #8

I had tried to do that on the console ("addwitnessaddress [the_legacy_address_that_appeared]", but it gave me the error:

"Public key or redeemscript not known to wallet, or the key is uncompressed (code -4)"

(I did not rescan, as it seemed the addwitnessaddress command wasn't successful.)

There's something I do not know or understand about segwit's functionning, and so I have no clue how to progress forward with that.
What would that mean?
Oh, since you are coming from Armory, this is going to be slightly painful.

Segwit only allows compressed public keys, but Armory only uses uncompressed public keys. In order to use Segwit, Armory will compress the keys on-the-fly, but the export will still give you the uncompressed version.

Go to https://github.com/pointbiz/bitaddress.org and download the git repo. That is the source code for bitaddress.org which is a website that is reasonable trusted to not steal your private keys. By downloading the source code, you can access the website locally and thus not send any private keys to a website. Even so, once you finish doing this, you should move your coins immediately to a new address and never use this address (both the segwit and legacy versions) ever again.

Open the file bitaddress.org.html in your browser (double clicking it should do that automatically) and choose the option for "Wallet Details". Enter your private key into the box and click "View Details". Scroll down and copy the string from where it says "Private Key WIF compressed". It should begin with a "K".

Import that string into Bitcoin Core. It is the private key that corresponds to the compressed public key. Then use addwitnessaddress on the imported address.

RaviMoll (OP)
Newbie
*
Offline Offline

Activity: 14
Merit: 1


View Profile
January 05, 2018, 02:37:27 AM
 #9

Perfect!  It looks exactly like what I was needing!

I should be able to convert the private keys from the uncompressed to the compressed format using a local version of bitaddress.org - now that I know this is what I need to do!

Will do that and report here.
Many thanks for your much appreciated help.
RaviMoll (OP)
Newbie
*
Offline Offline

Activity: 14
Merit: 1


View Profile
January 05, 2018, 02:54:15 AM
 #10

Yes, it did work!   Smiley

Much gratitude for your help and for sharing your knowledge, achow101.  You made my day!

And I feel I understand a tiny bit more of the workings of Bitcoin now.  Still a long way to go...
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!