6

How does importing private keys work?

I have previously imported the private key for a 1Archive... address into Bitcoin Core and noted then it added an address like 1AXbRq... and I didn't follow it up further.

Today I have exported the private key for a 3... address from Bitcoin Core and imported it in Electrum. Electrum adds a 1... address and doesn't see any of the transactions.

How does this work? I understand that there is an underlying 1... address behind a SegWit address but how would I spend any BTC if it is not showing in my wallet balance? What else should I do?

If there is an answered question for this already on Bitcoin.SE I could not find it.

My private key begins with L.

  • Was the address that started with 3 a P2WPKH address? If so, that might help: bitcoin.stackexchange.com/q/72899/38618 – MCCCS Mar 24 '18 at 10:07
  • @MCCCS Okay, that's actually close. I have a 3... address not a bc1... address. I have hope it is going to be easily solvable. – Willtech Mar 24 '18 at 10:25
  • @MCCCS Actually, tried that method, Electrum says that the key cannot be imported. My priv key starts with L. – Willtech Mar 24 '18 at 10:29
  • It's completly irrelevant that your private key start with "L". Don't share it! – Alpha Mar 24 '18 at 14:44
  • ICIN, the official download for Electrum is from bitcoin.org/en/wallets/desktop/windows/electrum – Willtech Mar 29 '18 at 13:02
4

I suspect you can import it directly from the console within Electrum (based on this PR). Currently, Electrum does now allow importing individual p2wpk inside p2sh addresses (the 3 segwit addresses). You can, however, still import an entire seed by using a BIP49 derivation path.

Try running the following in the electrum console:

key = 'your_key'
txin_type, secret, compressed = bitcoin.deserialize_privkey(key)
wif2 = bitcoin.serialize_privkey(secret, compressed, 'p2wpkh-p2sh')
print(wif2)

Then import the wif2 which it prints out

  • That works. It imports the correct address. – Willtech Mar 24 '18 at 11:21
  • Good to know! I wasn't super sure, and currently away from a machine with electrum on it. Thank you for confirming. – Raghav Sood Mar 24 '18 at 11:23
  • Note since 3.1 you can just prepend "p2wpkh-p2sh:" to the private key before importing it. – Abdussamad Mar 25 '18 at 6:17
6

Prepend "p2wpkh-p2sh:" to the private key before importing it into Electrum. For example:

p2wpkh-p2sh:5Kkzs8XrJNAmf9VQDFeGBfaRvSByAvPK6DbDXw5BVqswWaXSG2Y

  • I cannot confirm this - I tried it on my priv key and I get an error but, then again I have already imported it. – Willtech Mar 25 '18 at 7:24
  • @Willtech it only works with 3.1 and above. – Abdussamad Mar 25 '18 at 7:36
  • Just checked my version, it is indeed not 3.1 and above. – Willtech Mar 25 '18 at 7:39
  • you made me cry, after 6 hours of searching and trying. I wish I could give you +100 upvotes. Thank you. – Ashkan May 8 '18 at 2:40
-1

"I have previously imported the private key for a 1Archive... address into Bitcoin Core and noted then it added an address like 1AXbRq... and I didn't follow it up further."

First of all, I won't be answering the first question. It just sounds weird, and 99% it's caused by a mistake.

How does this work? I understand that there is an underlying 1... address behind a SegWit address but how would I spend any BTC if it is not showing in my wallet balance? What else should I do?

Here's how importing a P2PKH address works:

WIF result is affected by three parameters: Privkey type (a byte for BTC private keys), the private key (that also contains which y coordinate the pubkey has, if we want the compressed pubkey), and an extra 0x01 byte if we want the compressed pubkey. There's only one public key that can be generated using that WIF.

Here's how importing a P2SH address works:

1) Dump the WIF of the P2SH address

2) Import the WIF

3) Make a transaction, and watch how your wallet or Bitcoin Core doesn't recognize the transaction.

It won't recognize the transaction, because there's infinite number of P2SH addresses one can create using the WIF (Note: script has a size limit, so it's not infinite)!

To inform your wallet about your P2SH address, you should also import the script. And, this is not supported by 99.9% of the wallets. (However, the wallets can import Witness addresses, as they're standardized and widely used) That's why Electrum doesn't see your P2WPKH address, if you don't tell it to use the Witness address.

  • 1
    p2wpkh-p2sh scripts are standardized in the bip. As long as you prepend "p2wpkh-p2sh:" to the WIF Electrum will recognize it as such in Electrum 3.1 or newer. In the case of 3.0.x you have to convert the WIF which you can do using the script @RaghavSood posted or this menu based one here. – Abdussamad Mar 25 '18 at 8:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.