<p>There are a few things to consider here.</p>

<p>First, do you know the path of the HD wallet? You can find out what type of path structure your wallet is using, and if the address with the unspent transactions was the very first one, then it would be account 0, for example.</p>

<p><a href="https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki" rel="nofollow noreferrer">See this on BIP44 paths...</a></p>

<p>If you know the path structure, and you know the exact address you are looking for at a given path, then you could do something like this using bitcoinjs-lib:</p>

<pre><code>const bip39 = require("bip39")
const bitcoin = require("bitcoinjs-lib")

const network = bitcoin.networks.bitcoin

for (const phrase of phrases) {
    const seed = await bip39.mnemonicToSeed(phrase)
    const root = bitcoin.bip32.fromSeed(seed, network)
    const path = "m/44'/0'/0'/0"
    const child = root.derivePath(path)
    const { address } = bitcoin.payments.p2sh({
        redeem: bitcoin.payments.p2wpkh({
            pubkey: child.publicKey,
            network
        }),
        network
    })

    if (address === '3...') {
        //this is yours
    }
}
</code></pre>

<p>Note that this example is for P2WPKH wrapped addresses (3 prefix). You would need to change this a bit depending on the type of address you are trying to match.</p>

CC BY-SA 4.0
2019-12-11T23:14:20.553Z
Hi Michael, unfortunately I do not have the path of the HD wallet.  I have a list of seeds (and thus can derive the master public key) and was thinking of scanning the blockchain (blockchain.com) using the master public key to see the funds in the wallet.  I do know how many bitcoins I have in that account.  Do you have any other suggestions on how to do this without the path? I can always derive addresses but that will take very long.
Sameer L
CC BY-SA 4.0
2019-12-11T23:58:26.410Z
@SameerLal indeed! You can obtain the xpubs from the list of seeds you have by looping through them as I have shown above, and then check on https://www.blockchain.com/btc/xpub/<xpub_address> to see if you've found your match.
Michael Rodriguez
CC BY-SA 4.0
2019-12-13T00:45:15.107Z
thank you!  This works well.  Sorry for so many questions, but do you happen to know of a python module or any code that'll allow me to derive the xpub address from bip39 seed without having to do any heavy lifting? just trying to save time.
Sameer L
CC BY-SA 4.0
2019-12-13T00:54:14.017Z
Sure no problem. Is python your preference? The snippet I posted above uses bitcoinjs-lib which is pretty well maintained and easy to use, but if node/JavaScript isn’t your thing I can help you achieve this with a python library as well.
Michael Rodriguez
CC BY-SA 4.0
2019-12-13T02:28:30.173Z
Yeah I'd prefer python because I already have a (fairly long) script I wrote in python for other parts.  If you do not know of any other alternatives, no worries, I can spend some time trying to pythonify the code you wrote.
Sameer L
CC BY-SA 4.0
2019-12-13T03:00:51.893Z
This looks promising: https://github.com/ranaroussi/pywallet/blob/master/README.rst except in your case you’ll want to provide your mnemonics from a list rather than using the generate() method.
Michael Rodriguez
CC BY-SA 4.0
2019-12-13T16:53:00.810Z
this looks interesting, except I think in the readme it is creating a wallet derived from the phrase.  the xpub key in the json is different than the one I see on Ian's site: https://iancoleman.io/bip39/.  I'm actually not sure why this is the case, any ideas?
Sameer L
CC BY-SA 4.0
2019-12-13T17:18:46.863Z
I am thinking of something like this:

`for seed in checksum_candidates:    

    w = wallet.create_wallet(network="BTC", seed=seed)

    xpubkey = w['xpublic_key']

    url = f'https://blockchain.info/multiaddr?active={xpubkey}'

    time.sleep(1)

    r = requests.get(url = url, verify=False)

    response_dict = json.loads(r.text)

    print(response_dict['wallet']['final_balance']) `

but am worried this method might not work for some reason since i'm getting a balance of 0 for all of my candidate seeds (false negatives?)
Sameer L
CC BY-SA 4.0
2019-12-13T18:56:21.887Z
It seems the python lib uses the path `m/44'/0'/0'/` while Ian’s site uses `m/44'/0'/0/` without the last `’`. But the path would only affect the derived addresses, not the root xpub. Are you using the root xpub to query the transaction histories?
Michael Rodriguez
CC BY-SA 4.0
2019-12-11T21:08:48.210Z
2019-12-11T21:08:48.210Z
Michael Rodriguez
<p>From having a list of bip39 seeds, is there any way of recovering a wallet?  In particular, I have a list of ~100 seeds--one of which is mine--and need an automate way of figuring out which is valid and has my funds.
Thanks</p>

<bitcoin-core><wallet-recovery><mnemonic-seed>
Wallet Recovery with Bip39 Seed
Sameer L
# Wallet Recovery with Bip39 Seed

(Asked by: username_0 on 2019-12-11)

From having a list of bip39 seeds, is there any way of recovering a wallet? In particular, I have a list of ~100 seeds--one of which is mine--and need an automate way of figuring out which is valid and has my funds.
Thanks

**Tags:** bitcoin-core, wallet-recovery, mnemonic-seed


---

## 1 answers

### Answer by username_1 on 2019-12-11. Score: 1

There are a few things to consider here.

First, do you know the path of the HD wallet? You can find out what type of path structure your wallet is using, and if the address with the unspent transactions was the very first one, then it would be account 0, for example.

[See this on BIP44 paths...](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki)

If you know the path structure, and you know the exact address you are looking for at a given path, then you could do something like this using bitcoinjs-lib:

```
const bip39 = require("bip39")
const bitcoin = require("bitcoinjs-lib")

const network = bitcoin.networks.bitcoin

for (const phrase of phrases) {
    const seed = await bip39.mnemonicToSeed(phrase)
    const root = bitcoin.bip32.fromSeed(seed, network)
    const path = "m/44'/0'/0'/0"
    const child = root.derivePath(path)
    const { address } = bitcoin.payments.p2sh({
        redeem: bitcoin.payments.p2wpkh({
            pubkey: child.publicKey,
            network
        }),
        network
    })

    if (address === '3...') {
        //this is yours
    }
}

```

Note that this example is for P2WPKH wrapped addresses (3 prefix). You would need to change this a bit depending on the type of address you are trying to match.

> **Comments:**
> **username_0**: Hi username_1, unfortunately I do not have the path of the HD wallet.  I have a list of seeds (and thus can derive the master public key) and was thinking of scanning the blockchain (blockchain.com) using the master public key to see the funds in the wallet.  I do know how many bitcoins I have in that account.  Do you have any other suggestions on how to do this without the path? I can always derive addresses but that will take very long.  
> **username_1**: @SameerLal indeed! You can obtain the xpubs from the list of seeds you have by looping through them as I have shown above, and then check on https://www.blockchain.com/btc/xpub/<xpub_address> to see if you've found your match.  
> **username_0**: thank you!  This works well.  Sorry for so many questions, but do you happen to know of a python module or any code that'll allow me to derive the xpub address from bip39 seed without having to do any heavy lifting? just trying to save time.  
> **username_1**: Sure no problem. Is python your preference? The snippet I posted above uses bitcoinjs-lib which is pretty well maintained and easy to use, but if node/JavaScript isn’t your thing I can help you achieve this with a python library as well.  
> **username_0**: Yeah I'd prefer python because I already have a (fairly long) script I wrote in python for other parts.  If you do not know of any other alternatives, no worries, I can spend some time trying to pythonify the code you wrote.  
> **username_1**: This looks promising: https://github.com/ranaroussi/pywallet/blob/master/README.rst except in your case you’ll want to provide your mnemonics from a list rather than using the generate() method.  
> **username_0**: this looks interesting, except I think in the readme it is creating a wallet derived from the phrase.  the xpub key in the json is different than the one I see on Ian's site: https://iancoleman.io/bip39/.  I'm actually not sure why this is the case, any ideas?  
> **username_0**: I am thinking of something like this:  `for seed in checksum_candidates:          w = wallet.create_wallet(network="BTC", seed=seed)      xpubkey = w['xpublic_key']      url = f'https://blockchain.info/multiaddr?active={xpubkey}'      time.sleep(1)      r = requests.get(url = url, verify=False)      response_dict = json.loads(r.text)      print(response_dict['wallet']['final_balance']) `  but am worried this method might not work for some reason since i'm getting a balance of 0 for all of my candidate seeds (false negatives?)  
> **username_1**: It seems the python lib uses the path `m/44'/0'/0'/` while Ian’s site uses `m/44'/0'/0/` without the last `’`. But the path would only affect the derived addresses, not the root xpub. Are you using the root xpub to query the transaction histories?  

---

