Bitcoin Forum
October 15, 2018, 08:50:48 PM *
News: Make sure you are not using versions of Bitcoin Core other than 0.17.0 [Torrent], 0.16.3, 0.15.2, or 0.14.3. More info.
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: [GUIDE] Importing Electrum Segwit Private Key Into Bitcoin Core (And Vice Versa)  (Read 106 times)
Xynerise
Sr. Member
****
Offline Offline

Activity: 280
Merit: 280

39twH4PSYgDSzU7sLnRoDfthR6gWYrrPoD


View Profile
April 24, 2018, 08:00:01 AM
Merited by LoyceV (4), OmegaStarScream (3), achow101 (2), pooya87 (2), Lucius (2), ranochigo (1), HCP (1)
 #1

Usually, when you import a segwit private key from Bitcoin Core to Electrum, Electrum generates a legacy address (starting with '1') instead of a Segwit address (starting with '3' or 'bc1') because Bitcoin Core uses the WIF for all address types while Electrum has a custom WIF for different types of addresses so each WIF corresponds to 1 bitcoin address.
Also, because of this, you're also unable to import a segwit WIF from Electrum into Bitcoin Core because Core doesn't understand the custom WIF.

However, Electrum internally maintains backwards compatibility so you can convert an Electrum custom WIF to one Core understands.

How To Convert An Electrum segwit WIF to standard WIF

For P2SH-P2WPKH addresses:
Open the console in Electrum and type the following code . (Press enter after each line)
Code:
key = 'L4wAtJ8RYaxtRYZxUwZRH8qGYVv1LUP3RAh9ER9KK2HeTXW6v4Ru'
txin_type, secret, compressed = bitcoin.deserialize_privkey(key)
wif2 = bitcoin.serialize_privkey(secret, compressed, 'p2wpkh-p2sh')
print(wif2)
Replace "L4..." with the private key you got from Electrum and leave the quotation marks as is.
It should print a WIF that you can import into Bitcoin Core.

For P2WPKH addresses (Bech32)
Type the following code, replacing the private key there with yours.
Code:
key = 'LAst2SKVNx36PUY2q49cyLCcpze1YMvdJ66z3uKuiyaLKTVVsH3J'
txin_type, secret, compressed = bitcoin.deserialize_privkey(key)
wif2 = bitcoin.serialize_privkey(secret, compressed, 'p2pkh')
print(wif2)
It should print a private key you can import into Bitcoin Core to get your Bech32 address.


How To Import Segwit WIF from Bitcoin Core to Electrum
This one is simple to do.
NB: For this to work you need to be on Electrum version 3.1.1 and above


For P2SH-P2WPKH addresses (Addresses starting with "3")
Just add p2wpkh-p2sh: directly in front of your  private key.
For example
Code:
p2wpkh-p2sh:5BitcoinPrivateKey
This should generate the corresponding p2wpkh-p2sh bitcoin address.

For P2WPKH addresses (Bech32, starting with 'bc1')
This time we'll add p2wpkh: in front of the private key.
For example
Code:
p2wpkh:5PrivateKey
This should generate the corresponding Bech32 address
1539636648
Hero Member
*
Offline Offline

Posts: 1539636648

View Profile Personal Message (Offline)

Ignore
1539636648
Reply with quote  #2

1539636648
Report to moderator
1539636648
Hero Member
*
Offline Offline

Posts: 1539636648

View Profile Personal Message (Offline)

Ignore
1539636648
Reply with quote  #2

1539636648
Report to moderator
1539636648
Hero Member
*
Offline Offline

Posts: 1539636648

View Profile Personal Message (Offline)

Ignore
1539636648
Reply with quote  #2

1539636648
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1539636648
Hero Member
*
Offline Offline

Posts: 1539636648

View Profile Personal Message (Offline)

Ignore
1539636648
Reply with quote  #2

1539636648
Report to moderator
1539636648
Hero Member
*
Offline Offline

Posts: 1539636648

View Profile Personal Message (Offline)

Ignore
1539636648
Reply with quote  #2

1539636648
Report to moderator
1539636648
Hero Member
*
Offline Offline

Posts: 1539636648

View Profile Personal Message (Offline)

Ignore
1539636648
Reply with quote  #2

1539636648
Report to moderator
Abdussamad
Legendary
*
Offline Offline

Activity: 1890
Merit: 1071



View Profile WWW
April 24, 2018, 12:46:50 PM
Merited by Xynerise (2), HCP (1)
 #2

If you use Electrum 3.1 or newer to view your private keys it'll display them in "script_type:priv_key_in_standard_wif" so there is nothing to convert. Just remove the colon and whatever comes before it.

Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!