<p>If you are ok with a third party service check out the <a href="https://blockchain.info/api" rel="nofollow">Blockchain API</a>.</p>

<p>They have a C# library and it's fairly easy to use.</p>

<p>If you need only the balance of an address you can use the code below as described <a href="https://github.com/blockchain/api-v1-client-csharp/blob/master/docs/blockexplorer.md" rel="nofollow">on their BlockExplorer page</a>:</p>

<pre><code> // calculate the balanace of an address by fetching a list of all its unspent outputs
 var outs = blockExplorer.GetUnspentOutputs("1EjmmDULiZT2GCbJSeXRbjbJVvAPYkSDBw");
 long totalUnspentValue = outs.Sum(x =&gt; x.Value);
</code></pre>

CC BY-SA 3.0
2016-06-07T18:05:50.413Z
I tried to implement your example, but it gives only various error messages: using System;
using System.Collections.Generic;
using System.Linq;
using Info.Blockchain.API;
using Info.Blockchain.API.BlockExplorer;

namespace ConsoleApplication3
    {
    class Program
        {
        static void Main(string[] args)
        {
            var blockExplorer = new BlockExplorer();
            var outs = blockExplorer.GetUnspentOutputs("1EjmmDULiZT2GCbJSeXRbjbJVvAPYkSDBw");
            long totalUnspentValue = outs.Sum(x => x.Value);
            }
        }
    }
emcor
CC BY-SA 3.0
2016-06-07T20:58:37.887Z
It appears this library is outdated and the new version requires a wallet account on their website. However, I am looking for an independent solution because it is faster.
emcor
CC BY-SA 3.0
2016-06-08T08:52:21.587Z
@emcor You're right! I've just tested their current version and it seems that they changed a lot and did not update their samples in the documentation. They have their async methods generated and the BlockExplorer must be accessed through the BlockchainApiHelper which needs some parameters we get after applying for an API key (https://api.blockchain.info/v2/apikey/request/ or https://blockchain.info/api/api_create_code). Sorry for the outdated information, my bad!
Andras
CC BY-SA 3.0
2016-06-07T14:08:28.027Z
2016-06-07T14:08:28.027Z
Andras
<p>Take a look at Blockparser: <a href="https://github.com/znort987/blockparser" rel="nofollow">https://github.com/znort987/blockparser</a>**</p>

<p>It will let you parse blockchain data to verify balances (among other things)</p>

CC BY-SA 3.0
2016-06-07T07:33:33.610Z
Thank you. This package requires C++ and Unix, is there a solution in C# on windows?
emcor
CC BY-SA 3.0
2016-06-07T07:37:13.847Z
@emcor There may be but I am not familiar with one, sorry. Perhaps someone else can make a better suggestion.
dontmindme
CC BY-SA 3.0
2016-06-07T00:33:14.867Z
2016-06-07T00:33:14.867Z
dontmindme
<pre><code>using Info.Blockchain.API.BlockExplorer;
using Info.Blockchain.API.Models;

internal decimal CheckBalance(string[] base58Addresses)  {
    BlockExplorer be = new BlockExplorer();
    IEnumerable&lt;UnspentOutput&gt; outs = be.GetUnspentOutputsAsync(base58Addresses).Result;
    decimal totalUnspentValue = outs.Sum(x =&gt; x.Value.GetBtc());

    return totalUnspentValue;
 }
</code></pre>

CC BY-SA 3.0
2017-10-27T13:48:47.577Z
2017-10-27T13:48:47.577Z
Iman
<p>How can I get the bitcoin balance of a public key in C#?</p>

<p>E.g. for this public key: 1FqLoEpbQpMxow5bqEPpFbPVnBEbFcsg3J</p>

<p>How can I get its balance in C#?</p>

CC BY-SA 3.0
2016-06-07T13:26:54.313Z
That looks like an address to me, not a public key. Edited accordingly. Related unanswered question: [C# parse bitcoin blockchain to get balance of an address](http://bitcoin.stackexchange.com/q/37998/5406)
Murch
CC BY-SA 3.0
2018-04-02T02:53:57.657Z
Something like https://api.blockcypher.com/v1/btc/main/addrs/38DGj87axzmQiZeAd1w1y5FEmuu5a7pfBa
LF-DevJourney
<address><balance><c#>
How to get the bitcoin balance of a public key in C#?
emcor
# How to get the bitcoin balance of a public key in C#?

(Asked by: username_0 on 2016-06-06)

How can I get the bitcoin balance of a public key in C#?

E.g. for this public key: 1FqLoEpbQpMxow5bqEPpFbPVnBEbFcsg3J

How can I get its balance in C#?

**Tags:** address, balance, c#

> **Comments:**
> **username_1**: That looks like an address to me, not a public key. Edited accordingly. Related unanswered question: [C# parse bitcoin blockchain to get balance of an address](http://bitcoin.stackexchange.com/q/37998/5406)  
> **username_2**: Something like https://api.blockcypher.com/v1/btc/main/addrs/38DGj87axzmQiZeAd1w1y5FEmuu5a7pfBa  

---

## 3 answers

### Answer by username_3 on 2016-06-07. Score: 2

If you are ok with a third party service check out the Blockchain API.
They have a C# library and it's fairly easy to use.
If you need only the balance of an address you can use the code below as described on their BlockExplorer page:
 // calculate the balanace of an address by fetching a list of all its unspent outputs
 var outs = blockExplorer.GetUnspentOutputs("1EjmmDULiZT2GCbJSeXRbjbJVvAPYkSDBw");
 long totalUnspentValue = outs.Sum(x => x.Value);

> **Comments:**
> **username_0**: I tried to implement your example, but it gives only various error messages: using System; using System.Collections.Generic; using System.Linq; using Info.Blockchain.API; using Info.Blockchain.API.BlockExplorer;  namespace ConsoleApplication3     {     class Program         {         static void Main(string[] args)         {             var blockExplorer = new BlockExplorer();             var outs = blockExplorer.GetUnspentOutputs("1EjmmDULiZT2GCbJSeXRbjbJVvAPYkSDBw");             long totalUnspentValue = outs.Sum(x => x.Value);             }         }     }  
> **username_0**: It appears this library is outdated and the new version requires a wallet account on their website. However, I am looking for an independent solution because it is faster.  
> **username_3**: @username_0 You're right! I've just tested their current version and it seems that they changed a lot and did not update their samples in the documentation. They have their async methods generated and the BlockExplorer must be accessed through the BlockchainApiHelper which needs some parameters we get after applying for an API key (https://api.blockchain.info/v2/apikey/request/ or https://blockchain.info/api/api_create_code). Sorry for the outdated information, my bad!  

---

### Answer by username_4 on 2016-06-07. Score: 1

Take a look at Blockparser: <https://github.com/znort987/blockparser>\*\*

It will let you parse blockchain data to verify balances (among other things)

> **Comments:**
> **username_0**: Thank you. This package requires C++ and Unix, is there a solution in C# on windows?  
> **username_4**: @username_0 There may be but I am not familiar with one, sorry. Perhaps someone else can make a better suggestion.  

---

### Answer by username_5 on 2017-10-27. Score: 0

using Info.Blockchain.API.BlockExplorer;
using Info.Blockchain.API.Models;

internal decimal CheckBalance(string[] base58Addresses)  {
    BlockExplorer be = new BlockExplorer();
    IEnumerable outs = be.GetUnspentOutputsAsync(base58Addresses).Result;
    decimal totalUnspentValue = outs.Sum(x => x.Value.GetBtc());

    return totalUnspentValue;
 }


---

