Bitcoin Forum
June 14, 2024, 11:08:14 PM *
News: Voting for pizza day contest
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: How to list all the funded address from a HD wallet?  (Read 131 times)
I_love_Crypto (OP)
Newbie
*
Offline Offline

Activity: 12
Merit: 2


View Profile
January 18, 2024, 07:21:27 PM
 #1

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:)
odolvlobo
Legendary
*
Offline Offline

Activity: 4354
Merit: 3261



View Profile
January 18, 2024, 10:46:46 PM
 #2

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.


Join an anti-signature campaign: Click ignore on the members of signature campaigns.
PGP Fingerprint: 6B6BC26599EC24EF7E29A405EAF050539D0B2925 Signing address: 13GAVJo8YaAuenj6keiEykwxWUZ7jMoSLt
nc50lc
Legendary
*
Offline Offline

Activity: 2450
Merit: 5714


Self-proclaimed Genius


View Profile
January 19, 2024, 04:09:51 AM
 #3

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.

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
odolvlobo
Legendary
*
Offline Offline

Activity: 4354
Merit: 3261



View Profile
January 19, 2024, 08:23:22 AM
 #4

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.

Join an anti-signature campaign: Click ignore on the members of signature campaigns.
PGP Fingerprint: 6B6BC26599EC24EF7E29A405EAF050539D0B2925 Signing address: 13GAVJo8YaAuenj6keiEykwxWUZ7jMoSLt
I_love_Crypto (OP)
Newbie
*
Offline Offline

Activity: 12
Merit: 2


View Profile
January 19, 2024, 08:27:40 AM
 #5

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?
I_love_Crypto (OP)
Newbie
*
Offline Offline

Activity: 12
Merit: 2


View Profile
January 19, 2024, 08:39:28 AM
 #6

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.
I_love_Crypto (OP)
Newbie
*
Offline Offline

Activity: 12
Merit: 2


View Profile
January 19, 2024, 10:12:42 AM
 #7

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:)
I_love_Crypto (OP)
Newbie
*
Offline Offline

Activity: 12
Merit: 2


View Profile
January 19, 2024, 10:23:09 AM
 #8

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."
nc50lc
Legendary
*
Offline Offline

Activity: 2450
Merit: 5714


Self-proclaimed Genius


View Profile
January 20, 2024, 05:43:49 AM
 #9

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.

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
NotATether
Legendary
*
Offline Offline

Activity: 1638
Merit: 6897


bitcoincleanup.com / bitmixlist.org


View Profile WWW
January 20, 2024, 11:31:04 AM
 #10

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.

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!