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
1 Answer
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.
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.
-
1Hi 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. Dec 11, 2019 at 23:14
-
@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 blockchain.com/btc/xpub/<xpub_address> to see if you've found your match. Dec 11, 2019 at 23:58
-
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. Dec 13, 2019 at 0:45
-
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. Dec 13, 2019 at 0:54
-
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. Dec 13, 2019 at 2:28