<p>How about running a <a href="https://github.com/MetacoSA/QBitNinja" rel="nofollow">QBitNinja</a> server locally?  </p>

<pre><code>var client = new QBitNinjaClient(baseAddress:"specify host here, you probably want localhost", Network.TestNet);
var balanceModel = client.GetBalance(dest: [Add any IDestination here, like new BitcoinAddress("mivD5GHroixrzgjv6Ww73pV5R55PcL8JdM", Network.TestNet)], unspentOnly: true).Result;
if (balanceModel.Operations.Count == 0) 
    throw new Exception("No coins to spend");
var unspentCoins = new List&lt;Coin&gt;();
foreach (var operation in balanceModel.Operations)
            unspentCoins.AddRange(operation.ReceivedCoins.Select(coin =&gt; coin as Coin)); 
var balance = unspentCoins.Sum(x =&gt; x.Amount.ToDecimal(MoneyUnit.BTC));
</code></pre>

CC BY-SA 3.0
2016-10-26T19:42:43.370Z
2016-10-26T19:42:43.370Z
nopara73
<p>You can always use <a href="http://blockchainsql.io" rel="nofollow noreferrer">http://blockchainsql.io</a> to SQL query the Bitcoin blockchain.</p>

<p><em>Disclaimer</em>: I am the developer. </p>

CC BY-SA 3.0
2017-10-26T14:58:31.477Z
Just a note: when I click on GitHub/Twitter/Facebook or any contact link nothing happens.
nopara73
CC BY-SA 4.0
2021-11-13T04:17:11.747Z
@herman Can you provide a sample query to show how a getbalance equivalent query can be done on the sql database. For e.g in bitcoin cli console I run below set of commands to find balance of an address 1PWC7PNHL1SgvZaN7xEtygenKjWobWsCuf as below

`createwallet "wallet-1" true
loadwallet wallet-1
importaddress "1PWC7PNHL1SgvZaN7xEtygenKjWobWsCuf" "" false
getbalance`
kdas
CC BY-SA 4.0
2021-12-07T13:04:45.263Z
@kdas

# All deposits to bitmex

[https://blockchainsql.io/rR1gE3](https://blockchainsql.io/rR1gE3)

# All deposits to bitmex of at least 1 btc

[https://blockchainsql.io/FkuyZ7](https://blockchainsql.io/FkuyZ7)
Herman Schoenfeld
CC BY-SA 3.0
2016-12-28T02:58:29.917Z
2016-12-28T02:58:29.917Z
Herman Schoenfeld
<p>Is there a way to scan the Bitcoin blockchain in C# without using an external API? I am looking for the amount of spendable money of a Bitcoin address.</p>

<p>I am using NBitcoin. </p>

<pre><code>// create new key pair based on private key
NBitcoin.Key key = new NBitcoin.Key(privateKey, privateKey.Length, false);

// parse blk*.dat
// get balance for address key.PubKey.Hash
// How to do that?
</code></pre>

CC BY-SA 3.0
2015-06-15T22:16:56.843Z
Yes, this is certainly possible to do. The blockchain contains all the information needed.
Greg Hewgill
CC BY-SA 3.0
2015-06-16T01:18:54.207Z
@GregHewgill how he will query blockchain with NBitcoin?
Igor Barinov
CC BY-SA 3.0
2015-06-16T01:20:34.160Z
I'm afraid I don't know anything about how to use NBitcoin specifically. However, I've done exactly this with Python (for the blockchain of a different coin, but the structure is largely the same), so it's certainly possible.
Greg Hewgill
CC BY-SA 3.0
2015-07-26T11:58:12.213Z
http://www.codeproject.com/Articles/784519/NBitcoin-How-to-scan-the-Blockchain
Sebastian Xawery Wiśniowiecki
<blockchain><c#><nbitcoin>
C# parse bitcoin blockchain to get balance of an address
Pa Ddy
# C# parse bitcoin blockchain to get balance of an address

(Asked by: username_0 on 2015-06-15)

Is there a way to scan the Bitcoin blockchain in C# without using an external API? I am looking for the amount of spendable money of a Bitcoin address.

I am using NBitcoin.

```
// create new key pair based on private key
NBitcoin.Key key = new NBitcoin.Key(privateKey, privateKey.Length, false);

// parse blk*.dat
// get balance for address key.PubKey.Hash
// How to do that?

```

**Tags:** blockchain, c#, nbitcoin

> **Comments:**
> **username_1**: Yes, this is certainly possible to do. The blockchain contains all the information needed.  
> **username_2**: @username_1 how he will query blockchain with NBitcoin?  
> **username_1**: I'm afraid I don't know anything about how to use NBitcoin specifically. However, I've done exactly this with Python (for the blockchain of a different coin, but the structure is largely the same), so it's certainly possible.  
> **username_3**: http://www.codeproject.com/Articles/784519/NBitcoin-How-to-scan-the-Blockchain  

---

## 2 answers

### Answer by username_4 on 2016-10-26. Score: 4

How about running a [QBitNinja](https://github.com/MetacoSA/QBitNinja) server locally?

```
var client = new QBitNinjaClient(baseAddress:"specify host here, you probably want localhost", Network.TestNet);
var balanceModel = client.GetBalance(dest: [Add any IDestination here, like new BitcoinAddress("mivD5GHroixrzgjv6Ww73pV5R55PcL8JdM", Network.TestNet)], unspentOnly: true).Result;
if (balanceModel.Operations.Count == 0) 
    throw new Exception("No coins to spend");
var unspentCoins = new List<Coin>();
foreach (var operation in balanceModel.Operations)
            unspentCoins.AddRange(operation.ReceivedCoins.Select(coin => coin as Coin)); 
var balance = unspentCoins.Sum(x => x.Amount.ToDecimal(MoneyUnit.BTC));

```


---

### Answer by username_5 on 2016-12-28. Score: 0

You can always use <http://blockchainsql.io> to SQL query the Bitcoin blockchain.

*Disclaimer*: I am the developer.

> **Comments:**
> **username_4**: Just a note: when I click on GitHub/Twitter/Facebook or any contact link nothing happens.  
> **username_6**: @username_5 Can you provide a sample query to show how a getbalance equivalent query can be done on the sql database. For e.g in bitcoin cli console I run below set of commands to find balance of an address 1PWC7PNHL1SgvZaN7xEtygenKjWobWsCuf as below  `createwallet "wallet-1" true loadwallet wallet-1 importaddress "1PWC7PNHL1SgvZaN7xEtygenKjWobWsCuf" "" false getbalance`  
> **username_5**: @username_6  # All deposits to bitmex  [https://blockchainsql.io/rR1gE3](https://blockchainsql.io/rR1gE3)  # All deposits to bitmex of at least 1 btc  [https://blockchainsql.io/FkuyZ7](https://blockchainsql.io/FkuyZ7)  

---

