Restoring all addresses from a wallet

8 replies 86 views
the_orbitNewbie
Posts: 232 · Reputation: 30
#1Dec 24, 2023, 07:16 PM
Hey everyone, I'm trying to get a better grasp on how the wallet restore process works on a node. So here's the deal: I had a single wallet on my bitcoin node that had around 30 addresses. I used the "importprvkey" method to re-import this wallet, and it seemed to work fine since my wallet came back up. The problem is that I lost all the addresses except for the main one. For instance, I sent some coins to one of the addresses I had before the import, but now when I try to check the transactions for that address, my node says it can't pull up anything from it. So my question is: how can I restore a wallet and get back all the addresses I created before? Thanks for any help!
6 Reply Quote Share
Posts: 6 · Reputation: 201
#2Dec 24, 2023, 11:19 PM
If you import the private key it only retrieve the coins stored in that address so did you imported 30 privkeys? You need to use the recovery seeds/mnemonic phrase/seed phrase to import the wallet.
3 Reply Quote Share
the_orbitNewbie
Posts: 232 · Reputation: 30
#3Dec 25, 2023, 01:12 AM
Hello, Thank you for your reply ! The 30 addresses were on the same wallet. Because a wallet can have one or more addresses but at the end it's the same and only one wallet file. So when i restore this wallet i except that it will re-import all the addresses also. The "dumpprvkey" also return only one private key even if you have 30 addresses so i cannot restore 30 wallets even if i wanted. Thank you !
4 Reply Quote Share
Posts: 6 · Reputation: 201
#4Dec 25, 2023, 07:09 AM
"dumpprvkey" <address> will give private key of the specific address only in qt. AFAIK you can't retrieve seeds in qt wallet so either you can recover the wallet using wallet.dat file or 30 addresses with 30 private keys. Please correct me if I am wrong guys.
2 Reply Quote Share
the_orbitNewbie
Posts: 232 · Reputation: 30
#5Dec 25, 2023, 07:40 AM
What mean's qt please ? Thanks
1 Reply Quote Share
Posts: 705 · Reputation: 103
#6Dec 25, 2023, 10:26 AM
Which version of Bitcoin Core are you using? You might wanna try the prompt "rescan" after importing ur private key.  It tells Bitcoin Core to scan the blockchain for transactions associated with the imported private key. This process might take some time but once it is successfully completed, all addresses corresponding to the imported private key should now be part of your wallet. Another consideration would be the import of the wallet.dat because importing HD wallets via "importprvkey" might not restore all addresses that were associated. With the release of v0.13.0 all created wallets were HD wallets by default.
3 Reply Quote Share
the_orbitNewbie
Posts: 232 · Reputation: 30
#7Dec 25, 2023, 03:36 PM
Thank you for your reply ! I tried the -rescan option but it's seems it's not existing anymore since the v21 version. I also read that normally this scan should be automatic now that why they remove the flag. The problem is i still don't have all my addresses. An other solution would be to backup directly the file "*.dat" but that's mean each time i generate a new address  i need to backup the last version of this file right ? Or maybe someone has bettter solution ? Thanks you !
3 Reply Quote Share
Posts: 705 · Reputation: 103
#8Dec 27, 2023, 08:09 PM
Oh yes in the latest versions of Bitcoin Core the rescanning method got automatically initiated when its neccessary. But you can still do this manually if u wish. The command for that would be rescanblockchain - you can specify start and block heights for that aswell. This would look like this "rescanblockchain [start_block] [stop_block]" No its not neccessary to do that because all future addresses can be generated from the existing seed with HD wallets. But I would highly recommend to backup ur wallet.dat at regular intervals. Especially with big changes regarding balance or something similar. You can also try the command "listreceivedbyaddress 0 true" which lists all addresses that received atleast a single transaction including those with zero balances.
2 Reply Quote Share
dr_atlasMember
Posts: 419 · Reputation: 65
#9Dec 27, 2023, 11:59 PM
Do you remember with what version of Bitcoin Core you created your wallet? Was it a HD wallet? I would say there's no "main address" in a Bitcoin Core wallet. You have external addresses which are used when you request a receive address and there are internal addresses which are used for change coins, e.g. when you have an transaction input of 0.1BTC and you want to send Bob 0.06BTC with a transaction fee of 0.00002BTC, your wallet will create automatically a change output to return the excess of 0.03998BTC as change into an internal change address of your wallet. I hope for you that you still have the original wallet.dat file OR you have dumped all your keys with bitcoin-cli dumpwallet "filename". It's important to dump all keys if you have a non-HD legacy wallet and if you dare to deal with unprotected private keys (not recommended on an online device). bitcoin-cli dumpprivkey "address" only gives you the private key for one particular address, which is definitely not enough in your case. To restore a non-HD legacy Bitcoin Core wallet you would need all private keys and key types (external and internal) to import. A HD wallet does generate all private keys, public keys and addresses from a single HD seed key (a specially marked private key with hdseed=1 in wallet dump file). I haven't done such a restore myself yet, but if you have a dump of such a HD seed key, it should be possible to open an empty HD wallet with no keys, import that HD seed key with bitcoin-cli sethdseed "true" "HD-seed-in-WIF-format" and a subsequent bitcoin-cli keypoolrefill would generate by default 1000 receive and change addresses which should be identical to your initial wallet. A bitcoin-cli rescanblockchain should then find all UTXOs of such a restaured wallet. Bitcoin Core descriptor wallets can be restaured quite easily if you have the correct private key descriptor and derivation path. The devil lies in details but to my knowledge it's even possible to restore a BIP-39 mnemonic words wallet in Bitcoin Core (with additional tools like the Iancoleman-script (download from Github, verify authenticity, use only offline on permanently air-gapped or disposable or agnostic devices!).
5 Reply Quote Share
?Reply
Sign in to reply to this topic

Related topics