Title: How to list all the funded address from a HD wallet? Post by: I_love_Crypto on January 18, 2024, 07:21:27 PM Hello Everyone,
My question will probably seem stupid, and i apologize for this but there is something i would like to understand. I opened a blockchain.com wallet and funded it. I made some transactions with it, and today the balance is 0.0001 BTC. So far so good. Then i made a copy of the 12 words mnemonic from the blockchain account. To have a better understanding how HD wallet works, i installed the Python bitcoinlib library using pip on my computer. Unfortunately it says: no transaction and list some addresses with no balance... Today i used another Python script: $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ from mnemonic import Mnemonic import bip32utils words="w1 w2 w3 w4 w5 w6 w7 w8 w9 w10 w11 w12" mnemon.check(words) seed = mnemon.to_seed(words) print(f'BIP39 Seed: {seed.hex()}\n') root_key = bip32utils.BIP32Key.fromEntropy(seed) root_address = root_key.Address() root_public_hex = root_key.PublicKey().hex() root_private_wif = root_key.WalletImportFormat() print('Root key:') print(f'\tAddress: {root_address}') print(f'\tPublic : {root_public_hex}') print(f'\tPrivate: {root_private_wif}\n') for i in range(10): for j in range(10): child_key = root_key.ChildKey(i).ChildKey(j) child_address = child_key.Address() child_public_hex = child_key.PublicKey().hex() child_private_wif = child_key.WalletImportFormat() print(f'Child key m/{i}/{j}:') print(f'\tAddress: {child_address}') print(f'\tPublic : {child_public_hex}') print(f'\tPrivate: {child_private_wif}\n') $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ I checked the balance of the Child key m/0/0, m/0/1, m/1/0, m/1/1... They all have a zero balance :( So my question is: how to get a list of the address corresponding to non zero balance from the seed of a HD wallet? Thanks a lot:) Title: Re: How to list all the funded address from a HD wallet? Post by: odolvlobo on January 18, 2024, 10:46:46 PM I checked the balance of the Child key m/0/0, m/0/1, m/1/0, m/1/1... They all have a zero balance :( So my question is: how to get a list of the address corresponding to non zero balance from the seed of a HD wallet? I don't know much about the modules you are using, but typical paths look like: m/84'/0'/0'/0/index m/44'/0'/0'/0/index Also, you can use https://iancoleman.io/bip39/ to check you code with test mnemonics. Title: Re: How to list all the funded address from a HD wallet? Post by: nc50lc on January 19, 2024, 04:09:51 AM Then i made a copy of the 12 words mnemonic from the blockchain account. You mean Blockchain's online wallet?-snip- So my question is: how to get a list of the address corresponding to non zero balance from the seed of a HD wallet? They use standard derivation paths of BIP44 for legacy and BIP84 for SegWit HD wallets. Here's info about the paths: bip-0044 (https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki#path-levels) | bip-0084 (https://github.com/bitcoin/bips/blob/master/bip-0084.mediawiki#public-key-derivation) And if you created a second or third "private key wallet" (not address), you'll need to modify the derivation path's account_index accordingly. Title: Re: How to list all the funded address from a HD wallet? Post by: odolvlobo on January 19, 2024, 08:23:22 AM I was aware of this website. However i don't feel comfortable typing a mnemonic online, even for testing purpose with low balance. You don't have to use funded addresses. Just check that the generated key pairs are the same. Title: Re: How to list all the funded address from a HD wallet? Post by: I_love_Crypto on January 19, 2024, 08:27:40 AM What is the address type? Have you tried to import the seed into a wallet such as electrum? If you do that, it should list all addresses for you. First of all, thanks for your suggestion, i appreciate. Yes indeed, works like a charm. Got the addresses with transactions. It turns out that the derivation path is m/84h/0h/0h. First time i use Electrum, i'm impressed. I tried to figure out the advantages and disadvantage of Electrum vs Ledger. Someone mention "security": https://www.bitdegree.org/crypto-wallet-comparison/ledger-nano-x-vs-electrum is this a reality or a myth? Title: Re: How to list all the funded address from a HD wallet? Post by: I_love_Crypto on January 19, 2024, 08:39:28 AM Then i made a copy of the 12 words mnemonic from the blockchain account. You mean Blockchain's online wallet?-snip- So my question is: how to get a list of the address corresponding to non zero balance from the seed of a HD wallet? Yes, indeed. And now i know that it is a SegWit HD wallets. I have to modify the script above... Thanks. Title: Re: How to list all the funded address from a HD wallet? Post by: I_love_Crypto on January 19, 2024, 10:12:42 AM Here are the modifications i made:
I changed: import bip_utils instead of import bip32utils and root_key = bip_utils.BIP84Key.fromEntropy(seed) instead of root_key = bip32utils.BIP32Key.fromEntropy(seed) but that doesn't work: AttributeError: module 'bip_utils' has no attribute 'BIP84Key' Any ideas? Thanks a lot, i appreciate your help:) Title: Re: How to list all the funded address from a HD wallet? Post by: I_love_Crypto on January 19, 2024, 10:23:09 AM What is the address type? Have you tried to import the seed into a wallet such as electrum? If you do that, it should list all addresses for you. First of all, thanks for your suggestion, i appreciate. Yes indeed, works like a charm. Got the addresses with transactions. It turns out that the derivation path is m/84h/0h/0h. First time i use Electrum, i'm impressed. I tried to figure out the advantages and disadvantage of Electrum vs Ledger. Someone mention "security": https://www.bitdegree.org/crypto-wallet-comparison/ledger-nano-x-vs-electrum is this a reality or a myth? "BIP39 seeds do not include a version number, which compromises compatibility with future software. We do not guarantee that BIP39 imports will always be supported in Electrum." Title: Re: How to list all the funded address from a HD wallet? Post by: nc50lc on January 20, 2024, 05:43:49 AM Any ideas? Thanks a lot, i appreciate your help:) I've edited your code to work in legacy addresses at derivation path m/44'/0'/0'/0/0~19:Code: import bip32utils You can test the mnemonic seed above in IanColeman's BIP39 tool and compare the results in BIP44 tab. Unfortunately, bip32utils doesn't support SegWit so even if you put the correct derivation path index (84) for "purpose", it'll only display legacy address but with the correct public and private keys of your Blockchain web wallet's SegWit addresses. You'll have to use another library to display the correct address. Note: The "H" in the derivation paths in the result means that it's derived with "hardened" derivation path. You can increase the range of "account" depending on how many extra private key wallets you've created in 'Accounts and Addresses' page. Title: Re: How to list all the funded address from a HD wallet? Post by: NotATether on January 20, 2024, 11:31:04 AM You'll need to hook up to Blockcypher's API or any -txindex fullnode or Esplora node in order to query the address balance.
A little warning though, if you are generating hundreds of addresses from your seed, it will burn through your Blockcypher quota quite quickly. Unfortunately, bip32utils doesn't support SegWit so even if you put the correct derivation path index (84) for "purpose", it'll only display legacy address but with the correct public and private keys of your Blockchain web wallet's SegWit addresses. You'll have to use another library to display the correct address. You can make most things support Segwit addresses by using sipa's (Pieter Wuille) bech32 library on Github and feed the public key Ripemd160 hash into that. |