decred.org/dcrdex@v1.0.5/docs/wiki/Native-BTC-Wallet-Recovery-and-Rescanning.md (about) 1 # BTC Wallet Recovery and Rescanning 2 3 ## Opening the BTC Wallet Settings 4 5 In this guide, we will be using the Native BTC wallet that is built into DEX and you should learn how to navigate to the settings view. The settings view is where you can reinitialize the wallet, rescan the wallet, etc. 6 7 1. Navigate to the `Wallets` page (`/wallets`) and select the Bitcoin wallet if it is not already selected. 8 2. Click the `Settings` button that has a gears icon to open the settings dialog. 9 10 <img alt="BTC Wallet Settings View" src="./images/btc-wallet-page-for-settings.png" width="300"/> 11 12 ## Reinitializing the Native BTC Wallet 13 14 If the native BTC wallet is corrupted, the `dexc.log` (located at `~/.dexc/mainnet/logs` for Linux, `~/Library/Application\ Support/Dexc/mainnet/logs`, for MacOS and `C:\Users\<Username>\AppData\Dexc\mainnet` for windows) may have a message containing "wallet not found", such as: 15 16 > [ERR] CORE: Unable to connect to **btc** wallet (start and sync wallets BEFORE starting dex!): **connectWallet: failed to connect btc wallet: connect failure: wallet not found** 17 18 Note **btc** in the above message, and **wallet not found**. This may also say something about db corruption, or similar errors, which may also be addressed as follows. 19 20 In this case, the Wallets page (`/wallets`) will still show the wallet since it was previously configured, just that it is not synchronized and cannot be unlocked or connected. It will look like this: 21 22 <img alt="BTC Wallet View" src="./images/unloaded-btc-wallet.png" width="300"/> 23 24 To reinitialize the wallet, [open the wallet settings dialog](#opening-the-btc-wallet-settings) and click the `Recover` button: 25 26 <img alt="BTC Wallet Settings View" src="./images/btc-wallet-settings.png" width="300"/> 27 28 The `dexc.log` should say: 29 30 > \[DBG\] CORE\[btc\]\[SPV\]: Starting native BTC wallet... 31 32 The wallet will begin re-synchronizing. This may take several minutes. 33 34 **IF** this process results in errors, it may be necessary to go to the folder containing the wallet data and **delete the wallet.db so it may be regenerated** from your application seed. To do this: 35 36 1. Shutdown DEX. 37 2. Open the wallet directory. For mainnet, this would be: 38 - `~/.dexc/mainnet/assetdb/btc/mainnet/` on Linux 39 - `~/Library/Application\ Support/Dexc/mainnet/assetdb/btc/mainnet/` on MacOS 40 - `C:\Users\<Username>\AppData\Dexc\mainnet\assetdb\btc\mainnet` on Windows. 41 There may be a wallet.db file in this folder, which you should rename wallet.db.bak. 42 3. Startup and login to DEX. 43 4. \[Open the BTC wallet settings\](#opening-the-btc-wallet-settings) and click `Recover` again. 44 45 If you still encounter any error in the logs or notification, you can reach out to us on our chat channels. We will be happy to help you out. 46 47 ## Rescanning the wallet 48 49 In rare circumstances, the wallet may need to rescan the blockchain for missed transactions. This is a process that can take several hours, depending on the number of transactions in the wallet. 50 51 To rescan the wallet, [open the wallet settings dialog](#opening-the-btc-wallet-settings) and click the `Rescan` button. You will a message with a green check icon if the rescan was successful. 52 53 **IF** you wish to force a rescan, you can do so by following these steps: 54 55 1. Delete the wallet.db file in the `assetdb/btc/mainnet/` (for mainnet) folder as described at the end of the previous section. Start DEX and log in. Follow the instructions in [the Reinitializing the Native BTC Wallet section](#reinitializing-the-native-btc-wallet) to reinitialize the wallet and begin a resync. 56 2. OR (**safest option**) use the `dropwtxmgr` tool on that wallet.db file. See the instructions in <https://github.com/btcsuite/btcwallet/blob/master/docs/force_rescans.md>. You will build that tool as described there and then run it on DEX's btc wallet.db. For example `dropwtxmgr --db ~/.dexc/mainnet/assetdb/btc/mainnet/wallet.db`. When you start DEX and login again, it will begin to rescan the wallet. 57 58 ## Full reinitialize 59 60 In addition to reinitializing or rescanning the BTC wallet.db file, you may also remove all of the chain data files to force resynchronization of all blockchain data used by the neutrino service that powers the wallet. To do this, shutdown DEX and delete all of the files in `assetdb/btc/mainnet/` (for mainnet), including `neutrino.db`, `reg_filter_headers.bin`, `block_headers.bin`, and `wallet.db`. You may keep `peers.json` to help with bootstrapping when you restart, but it may be deleted too. 61 62 Next, startup DEX and go to the Wallet page. [open the wallet settings dialog](#opening-the-btc-wallet-settings) and click `Recover` after ensuring it is currently showing the `Native` wallet option as in the [first section's screenshot](#reinitializing-the-native-btc-wallet).