<p>I am developing a Bitcoin wallet SPV and using 3rd party SDK for the same.</p>

<p>However, I tried to create wallet and it gets successfully created and I can also restore those wallets but amount and transactions not coming. Making amount always 0 as amount calculation depends on transactions.</p>

<pre><code>//
//  XORWallet.swift
//  
//
//  Created by Paresh Thakor on 06/07/19.
//

import UIKit

let KEY_MNEMONIC = "wallet_mnemonic"

class XORWallet: NSObject {
    static let shared = XORWallet()

    var peerGroup: WSPeerGroup?
    var wallet: WSHDWallet?

    func create(_ seed: WSSeed? = nil) -&gt; WSHDWallet? {
        let parameters: WSParameters = WSParametersForNetworkType(WSNetworkTypeMain)
        var theSeed: WSSeed? = seed
        parameters.scriptAddressVersion()

        if theSeed == nil {
            theSeed =  (WSSeedGenerator.sharedInstance()?.generateRandomSeed())!
        }

        if let s = theSeed {
            let store: WSBlockStore = WSMemoryBlockStore.init(parameters: parameters)
            wallet = WSHDWallet.init(parameters: parameters, seed: s)
            let downloader: WSBlockChainDownloader = WSBlockChainDownloader.init(store: store, wallet: wallet)
//            wallet?.usedAddresses()
            print(wallet?.usedAddresses()!)
            print(wallet?.receiveAddress()!)
            print(wallet?.sortedTransactions())
            print(theSeed?.mnemonic()!)
            let peerGroup: WSPeerGroup = WSPeerGroup.init(parameters: parameters)
            peerGroup.startConnections()
            NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: "WSPeerGroupDidStartDownload"), object: nil, queue: nil) {(note) in
                print("Jay Mataji")
            }
            peerGroup.startDownload(with: downloader)
            NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: "WSPeerGroupDidFinishDownload"), object: nil, queue: nil){(note) in
                print("Completed")
            }

            self.peerGroup = peerGroup
        }
        return wallet
    }

    func generateSeed() -&gt; WSSeed? {
        let theSeed: WSSeed? = WSSeedGenerator.sharedInstance()?.generateRandomSeed()
        return theSeed
    }

    func saveToUserDefaults() -&gt; Bool {
        if let w =  wallet,
            let m = w.seed()?.mnemonic() {
            let def = UserDefaults.standard
            def.set(m, forKey: KEY_MNEMONIC)
            def.synchronize()

            return true
        }

        return false
    }

    func loadSavedWallet() -&gt; WSHDWallet? {
        let def = UserDefaults.standard
        if let m = def.string(forKey: KEY_MNEMONIC) {
            let seed = WSSeed(mnemonic: m)
            return create(seed)
        }

        return create()
    }
}
</code></pre>

<p>Create a wallet like,</p>

<pre><code>if let wallet = XORWallet.shared.create(XORWallet.shared.generateSeed()) {
            print(wallet.allReceiveAddresses()!)
            print(wallet.balance())
        }
</code></pre>

<p>Please help me solving the issue as here <code>wallet.balance()</code> always comes 0. There is balance for this account.</p>

<p>I am  new to bitcoin dev and may messed up  something.</p>

CC BY-SA 4.0
2019-09-03T21:22:14.567Z
Are you rescanning the blockchain once you create your wallet? Or in the case of SPV "replaying" the chain once all your addresses are added to the bloom filter?
pinhead
CC BY-SA 4.0
2019-09-04T05:47:30.853Z
@pinhead  I did not really get you. As  mentioned  in code, I am creating wallet by `create()` and then access balance and address by specific methods. I don't get about bloom filters and "replaying" stuff.
Paresh Thakor
<bitcoin-core><client><bitcoin-cash><bitcoin-core-development><spv>
Bitcoin SPV not able to fetch transactions
Paresh Thakor
# Bitcoin SPV not able to fetch transactions

(Asked by: username_0 on 2019-09-01)

I am developing a Bitcoin wallet SPV and using 3rd party SDK for the same.
However, I tried to create wallet and it gets successfully created and I can also restore those wallets but amount and transactions not coming. Making amount always 0 as amount calculation depends on transactions.
//
//  XORWallet.swift
//  
//
//  Created by username_0 on 06/07/19.
//

import UIKit

let KEY_MNEMONIC = "wallet_mnemonic"

class XORWallet: NSObject {
    static let shared = XORWallet()

    var peerGroup: WSPeerGroup?
    var wallet: WSHDWallet?

    func create(_ seed: WSSeed? = nil) -> WSHDWallet? {
        let parameters: WSParameters = WSParametersForNetworkType(WSNetworkTypeMain)
        var theSeed: WSSeed? = seed
        parameters.scriptAddressVersion()

        if theSeed == nil {
            theSeed =  (WSSeedGenerator.sharedInstance()?.generateRandomSeed())!
        }

        if let s = theSeed {
            let store: WSBlockStore = WSMemoryBlockStore.init(parameters: parameters)
            wallet = WSHDWallet.init(parameters: parameters, seed: s)
            let downloader: WSBlockChainDownloader = WSBlockChainDownloader.init(store: store, wallet: wallet)
//            wallet?.usedAddresses()
            print(wallet?.usedAddresses()!)
            print(wallet?.receiveAddress()!)
            print(wallet?.sortedTransactions())
            print(theSeed?.mnemonic()!)
            let peerGroup: WSPeerGroup = WSPeerGroup.init(parameters: parameters)
            peerGroup.startConnections()
            NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: "WSPeerGroupDidStartDownload"), object: nil, queue: nil) {(note) in
                print("Jay Mataji")
            }
            peerGroup.startDownload(with: downloader)
            NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: "WSPeerGroupDidFinishDownload"), object: nil, queue: nil){(note) in
                print("Completed")
            }

            self.peerGroup = peerGroup
        }
        return wallet
    }

    func generateSeed() -> WSSeed? {
        let theSeed: WSSeed? = WSSeedGenerator.sharedInstance()?.generateRandomSeed()
        return theSeed
    }

    func saveToUserDefaults() -> Bool {
        if let w =  wallet,
            let m = w.seed()?.mnemonic() {
            let def = UserDefaults.standard
            def.set(m, forKey: KEY_MNEMONIC)
            def.synchronize()

            return true
        }

        return false
    }

    func loadSavedWallet() -> WSHDWallet? {
        let def = UserDefaults.standard
        if let m = def.string(forKey: KEY_MNEMONIC) {
            let seed = WSSeed(mnemonic: m)
            return create(seed)
        }

        return create()
    }
}

Create a wallet like,
if let wallet = XORWallet.shared.create(XORWallet.shared.generateSeed()) {
            print(wallet.allReceiveAddresses()!)
            print(wallet.balance())
        }

Please help me solving the issue as here wallet.balance() always comes 0. There is balance for this account.
I am  new to bitcoin dev and may messed up  something.

**Tags:** bitcoin-core, client, bitcoin-cash, bitcoin-core-development, spv

> **Comments:**
> **username_1**: Are you rescanning the blockchain once you create your wallet? Or in the case of SPV "replaying" the chain once all your addresses are added to the bloom filter?  
> **username_0**: @username_1  I did not really get you. As  mentioned  in code, I am creating wallet by `create()` and then access balance and address by specific methods. I don't get about bloom filters and "replaying" stuff.  

---

## 0 answers

