<p>You can't do it from the console, but you can do it through the python API.  Stuff like this is done in their test scripts all the time.</p>
<p>Look at the <a href="https://github.com/spesmilo/electrum/blob/4.0.3/electrum/tests/test_wallet_vertical.py#L283" rel="nofollow noreferrer">test_bip39_seed_bip84_native_segwit</a> in their github repo for some hints</p>
<p>Another alternative would be to convert your bip39 seed to an <code>xprv</code> and use the <code>restore</code> command line option with the newly minted <code>xprv</code>.</p>
<p>Here's some sample code to convert your mnemonic to an xprv.  Obviously change the derivation path and mnemonic seed:</p>
<pre><code>#!/usr/bin/env python3
from mnemonic import Mnemonic
from pycoin.symbols.btc import network as btc

code = (&quot;abandon abandon abandon abandon abandon abandon&quot; + 
        &quot; abandon abandon abandon abandon abandon about&quot;)
path = '84H/0H/0H'
mnemo = Mnemonic(&quot;english&quot;)

xprv = btc.keys.bip32_seed(mnemo.to_seed(code)
           ).subkey_for_path(path).hwif(as_private=True)

print(&quot;Issue the Electrum commands&quot;)
print(f&quot;\tconvert_xkey {xprv} p2wpkh-p2sh&quot;)
print(f&quot;\tconvert_xkey {xprv} p2wpkh&quot;)
</code></pre>
<p>Do keep in mind that Electrum imports are assumed to be at the <em>Account Extended Key</em> level.  This means that importing an <code>xprv</code> at the derivation path <code>m/5'</code> level (random example) will have you a first receive address of <code>m/5'/0/0</code> and your first change address of <code>m/5'/1/0</code>.  Only way around this behavior would require importing the WIF keys one at a time.  A simple change to the <code>pycoin</code> code, but there is no simple <code>xprv</code> way to do it.</p>

CC BY-SA 4.0
2020-09-23T20:27:43.393Z
Thx for the answer but would I be able to set derivation path or choose legacy or native segwit from the console when restoring the xprv?
super.yang
CC BY-SA 4.0
2020-09-23T20:38:19.533Z
@super.yang, yes.  Basically you will need to write some python with `pycoin` or `mnemonic` to go from `mnemonic+derivation` -> xprv, then you can use the electrum command `convert_xkey` to convert the xprv to yprv, or zprv.  I'll dig up some code and update the comment, but there is no path I can see that won't involve python
Dan
CC BY-SA 4.0
2020-09-23T03:13:49.137Z
2020-09-23T21:22:02.177Z
2020-09-23T21:22:02.177Z
Dan
<p>How would I restore a bitcoin wallet using the Electrum command line on Linux with a BIP39 mnemonic and custom derivation path?</p>
<p>I need to use m/0' for legacy and m/1' for native segwit?</p>
<p>I cannot find anything in the documentation about BIP39 mnemonics or using a custom derivation path without using the GUI interface of Electrum.</p>
<p>Thanks!</p>

<electrum><electrum-console>
Restore BIP39 mnemonic in Electrum using command line and custom derivation path?
super.yang
# Restore BIP39 mnemonic in Electrum using command line and custom derivation path?

(Asked by: username_0 on 2020-09-23)

How would I restore a bitcoin wallet using the Electrum command line on Linux with a BIP39 mnemonic and custom derivation path?

I need to use m/0' for legacy and m/1' for native segwit?

I cannot find anything in the documentation about BIP39 mnemonics or using a custom derivation path without using the GUI interface of Electrum.

Thanks!

**Tags:** electrum, electrum-console


---

## 1 answers

### Answer by username_1 on 2020-09-23. Score: 1 | Accepted answer

You can't do it from the console, but you can do it through the python API. Stuff like this is done in their test scripts all the time.

Look at the [test\_bip39\_seed\_bip84\_native\_segwit](https://github.com/spesmilo/electrum/blob/4.0.3/electrum/tests/test_wallet_vertical.py#L283) in their github repo for some hints

Another alternative would be to convert your bip39 seed to an `xprv` and use the `restore` command line option with the newly minted `xprv`.

Here's some sample code to convert your mnemonic to an xprv. Obviously change the derivation path and mnemonic seed:

```
#!/usr/bin/env python3
from mnemonic import Mnemonic
from pycoin.symbols.btc import network as btc

code = ("abandon abandon abandon abandon abandon abandon" + 
        " abandon abandon abandon abandon abandon about")
path = '84H/0H/0H'
mnemo = Mnemonic("english")

xprv = btc.keys.bip32_seed(mnemo.to_seed(code)
           ).subkey_for_path(path).hwif(as_private=True)

print("Issue the Electrum commands")
print(f"\tconvert_xkey {xprv} p2wpkh-p2sh")
print(f"\tconvert_xkey {xprv} p2wpkh")

```

Do keep in mind that Electrum imports are assumed to be at the *Account Extended Key* level. This means that importing an `xprv` at the derivation path `m/5'` level (random example) will have you a first receive address of `m/5'/0/0` and your first change address of `m/5'/1/0`. Only way around this behavior would require importing the WIF keys one at a time. A simple change to the `pycoin` code, but there is no simple `xprv` way to do it.

> **Comments:**
> **username_0**: Thx for the answer but would I be able to set derivation path or choose legacy or native segwit from the console when restoring the xprv?  
> **username_1**: @username_0, yes.  Basically you will need to write some python with `pycoin` or `mnemonic` to go from `mnemonic+derivation` -> xprv, then you can use the electrum command `convert_xkey` to convert the xprv to yprv, or zprv.  I'll dig up some code and update the comment, but there is no path I can see that won't involve python  

---

