Author

Topic: How to list all the funded address from a HD wallet? (Read 127 times)

legendary
Activity: 1568
Merit: 6660
bitcoincleanup.com / bitmixlist.org
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.
legendary
Activity: 2394
Merit: 5531
Self-proclaimed Genius
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
from bip32utils import BIP32_HARDEN
from mnemonic import Mnemonic

words="hidden common actress negative cactus quote hole filter aunt confirm neutral voice"
mnemo = Mnemonic("english")
seed = mnemo.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')

purpose = (44)
coin = (0)
for account in range(1):
    for chain in range(1):
        for address in range(20):
            child_key = root_key.ChildKey(purpose + BIP32_HARDEN).ChildKey(coin + BIP32_HARDEN).ChildKey(account + BIP32_HARDEN).ChildKey(chain).ChildKey(address)
            child_address = child_key.Address()
            child_public_hex = child_key.PublicKey().hex()
            child_private_wif = child_key.WalletImportFormat()
            print(f'Child key m/{purpose}H/{coin}H/{account}H/{chain}/{address}:')
            print(f'\tAddress: {child_address}')
            print(f'\tPublic : {child_public_hex}')
            print(f'\tPrivate: {child_private_wif}\n')

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.
newbie
Activity: 5
Merit: 0
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?
Might not work in the future:
"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."
newbie
Activity: 5
Merit: 0
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:)
newbie
Activity: 5
Merit: 0
Then i made a copy of the 12 words mnemonic from the blockchain account.
-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?
You mean Blockchain's online wallet?

Yes, indeed. And now i know that it is a SegWit HD wallets. I have to modify the script above...

Thanks.
newbie
Activity: 5
Merit: 0
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?
legendary
Activity: 4298
Merit: 3209
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.
legendary
Activity: 2394
Merit: 5531
Self-proclaimed Genius
Then i made a copy of the 12 words mnemonic from the blockchain account.
-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?
You mean Blockchain's online wallet?
They use standard derivation paths of BIP44 for legacy and BIP84 for SegWit HD wallets.
Here's info about the paths: bip-0044 | bip-0084

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.
legendary
Activity: 4298
Merit: 3209
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 Sad

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.

newbie
Activity: 5
Merit: 0
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 Sad

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:)
Jump to: