<p>The <code>downloadBlockChain()</code> method looks like it downloads the whole blockchain. It looks like the <code>PeerGroup.setFastCatchupTime</code> method might be helpful to prevent it from downloading full blocks before that time. I imagine you'll use a method or change a boolean value to only download block headers for your SPV wallet, but I don't know where that would be.</p>

<p><a href="https://bitcoinj.github.io/speeding-up-chain-sync" rel="nofollow noreferrer">https://bitcoinj.github.io/speeding-up-chain-sync</a> may be a useful reference.</p>

CC BY-SA 4.0
2019-02-19T17:14:56.790Z
2019-02-19T17:14:56.790Z
Vecna
<p>I am building a Bitcoin wallet with the BitcoinJ Library, after looking at the example of fetching a transaction that they have shown on their <a href="https://github.com/bitcoinj/bitcoinj/blob/master/examples/src/main/java/org/bitcoinj/examples/FetchTransactions.java" rel="nofollow noreferrer">github</a> it shows that you need to download the blockchain however. </p>

<p>When attempting to download the blockchain to view the balance of my wallet, it begins to lock up and become unusable. I have even tried downloading the blockchain in an async task like so, but still the app becomes completely unusable and the UI doesn't even load. What am I missing? I thought that the download wouldn't be that large as I am attempting to create an SPV wallet which from what I understand doesn't download the entire blockchain, or is this something I need to configure seperately?</p>

<pre><code>class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
         DownloadBlockchain().execute()
    }

    inner class DownloadBlockchain : AsyncTask&lt;Void, Int, String&gt;() {
        override fun doInBackground(vararg p0: Void?): String {
            Globals.peerGroup?.startAsync()
            Globals.peerGroup?.downloadBlockChain()
            return "complete"
        }

        override fun onPostExecute(result: String?) {
            super.onPostExecute(result)
            Globals.peerGroup?.stopAsync()
            Globals.wallet?.saveToFile(Globals.walletFile)
        }
     }
 }
</code></pre>

<bitcoinj><android>
When downloading the blockchain my application is become unusable, is there an issue with my code or am I using the BitcoinJ library incorrectly?
Ben Moore
# When downloading the blockchain my application is become unusable, is there an issue with my code or am I using the BitcoinJ library incorrectly?

(Asked by: username_0 on 2019-02-19)

I am building a Bitcoin wallet with the BitcoinJ Library, after looking at the example of fetching a transaction that they have shown on their [github](https://github.com/bitcoinj/bitcoinj/blob/master/examples/src/main/java/org/bitcoinj/examples/FetchTransactions.java) it shows that you need to download the blockchain however.

When attempting to download the blockchain to view the balance of my wallet, it begins to lock up and become unusable. I have even tried downloading the blockchain in an async task like so, but still the app becomes completely unusable and the UI doesn't even load. What am I missing? I thought that the download wouldn't be that large as I am attempting to create an SPV wallet which from what I understand doesn't download the entire blockchain, or is this something I need to configure seperately?

```
class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
         DownloadBlockchain().execute()
    }

    inner class DownloadBlockchain : AsyncTask<Void, Int, String>() {
        override fun doInBackground(vararg p0: Void?): String {
            Globals.peerGroup?.startAsync()
            Globals.peerGroup?.downloadBlockChain()
            return "complete"
        }

        override fun onPostExecute(result: String?) {
            super.onPostExecute(result)
            Globals.peerGroup?.stopAsync()
            Globals.wallet?.saveToFile(Globals.walletFile)
        }
     }
 }

```

**Tags:** bitcoinj, android


---

## 1 answers

### Answer by username_1 on 2019-02-19. Score: 1

The `downloadBlockChain()` method looks like it downloads the whole blockchain. It looks like the `PeerGroup.setFastCatchupTime` method might be helpful to prevent it from downloading full blocks before that time. I imagine you'll use a method or change a boolean value to only download block headers for your SPV wallet, but I don't know where that would be.

<https://bitcoinj.github.io/speeding-up-chain-sync> may be a useful reference.


---

