<p><a href="https://www.blockonomics.co/views/api.html#balance" rel="nofollow noreferrer">Blockonomics API</a> supports balance and tx history of xpub/ypub/zpub</p>
<p>You can use the following sites to search address balance/history of xpub/ypub/zpub :</p>
<ul>
<li><a href="https://blockpath.com/search/xpub?q=xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8" rel="nofollow noreferrer">Blockpath</a></li>
<li><a href="https://www.blockonomics.co/" rel="nofollow noreferrer">Blockonomics</a></li>
</ul>

CC BY-SA 4.0
2022-11-24T14:16:15.600Z
It looks like it requires registering an email address (and maybe also paying?), which I might not be willing to do, but I will check out https://github.com/blockonomics/blockonomics-node#methods. Thanks. I'm very surprised that Ledger hasn't provided an easier way to track balances. I don't want to have to code a solution for each blockchain.
Ryan
CC BY-SA 4.0
2022-11-24T14:41:18.340Z
Yes email address is required for the APIKey. Its free as you long as you query withing their limits https://www.blockonomics.co/views/api.html#limits
dark knight
CC BY-SA 4.0
2022-11-24T06:17:24.843Z
2022-11-24T06:17:24.843Z
dark knight
<p>I will not repeat the mental model of how keys, addresses, and balances work on Bitcoin, let's assume you're familiar with this: <a href="https://bitcoin.stackexchange.com/a/115830/137501">https://bitcoin.stackexchange.com/a/115830/137501</a></p>
<p>One more thing to note about:</p>
<blockquote>
<p>I still don't have the full answer, and the following is only for BTC (I'd prefer an answer that works across many blockchains)</p>
</blockquote>
<p>The answer you get for Bitcoin can only apply to other Bitcoin-tech blockchains (like Litecoin, Bitcoin Cash, etc.). Other blockchains like Ethereum use totally different schemes, which I'm not familiar with at all.</p>
<p>Ok, so you know that in order to find your UTXOs you need to find some good libraries that implement these 3 BIPs:</p>
<ul>
<li><a href="https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki" rel="nofollow noreferrer">BIP32 Hierarchical Deterministic Wallets</a></li>
<li><a href="https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki" rel="nofollow noreferrer">BIP39 Mnemonic code for generating deterministic keys</a></li>
<li><a href="https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki" rel="nofollow noreferrer">BIP44 Multi-Account Hierarchy for Deterministic Wallets</a></li>
</ul>
<p>Also, SatoshiLabs (Trezor wallet manufacturer) maintains a list of derivation paths for many blockchains:</p>
<ul>
<li><a href="https://github.com/satoshilabs/slips/blob/master/slip-0044.md" rel="nofollow noreferrer">SLIP-0044 : Registered coin types for BIP-0044</a></li>
</ul>
<p>On a higher level, you have to:</p>
<ol>
<li>Generate the master key from mnemonic</li>
<li>Generate the master xpub. Note that generating the master key and the xpub should be done on an offline device, and then copied over to the online device to preserve security of &quot;air-gapping&quot;. Maybe the Ledger device can export just the xpub? If that's possible then you can skip the risky business of doing it yourself.</li>
<li>Use the derivation path to produce a list of some <code>N</code> addresses</li>
<li>Scan the UTXO set against those addresses and tally the balance</li>
<li>If you want the wallet history and not just the current balance, you need to scan the entire blockchain against the list of addresses</li>
</ol>
<p>Note that wallets make a new address each time you receive payment, so the list will grow.
When you're restoring a wallet from seed they don't know the <code>N</code>, so what they do is they scan for some number of addresses, like 100, and then find the last address that was actually used, and then scan for 100 more from that one, until they get to the 100 which was never used.</p>
<p>So, how to do the scanning in steps 4. and 5.?
I'm not fully familiar with that but I can tell you where to look:</p>
<ol>
<li>If you're running your own node, find the <a href="https://developer.bitcoin.org/reference/rpc/" rel="nofollow noreferrer">node's RPC documentation</a>, and see if you can get most of the job done using the node's RPC</li>
<li>Use <a href="https://electrumx-spesmilo.readthedocs.io/en/latest/protocol.html" rel="nofollow noreferrer">Electrum APIs</a> to get what you need, either from a public server of from running your own Electrum server alongside your node.</li>
<li>Use Ledger APIs and talk to their servers the same way their wallet talks to them, but I'm not sure how well this is documented.</li>
</ol>
<p>With 2., there are plenty of public servers you could query, and the data can be verified in a <a href="https://bitcoin.stackexchange.com/a/115974/137501">trustless manner</a>, all you need are block headers.
However, the server may store your queries and IPs so there's a privacy loss trade-off.
If you don't want to use a server, you can run an <a href="https://github.com/cculianu/Fulcrum" rel="nofollow noreferrer">Electrum server</a> by yourself alongside your node, and the server will produce indexes from the blockchain data so an address history can be easily looked up.</p>

CC BY-SA 4.0
2022-11-20T13:47:39.300Z
There's lots to like in this answer (upvoted) but it might be worth mentioning that extracting private keys from a hardware wallet and using them in a general purpose PC has significant security drawbacks.
RedGrittyBrick
CC BY-SA 4.0
2022-11-20T19:32:50.350Z
Thanks, added a little note next to step 2: Note that generating the master key and the xpub should be done on an offline device, and then copied over to the online device to preserve security of "air-gapping". Maybe the Ledger device can export just the xpub? If that's possible then you can skip the risky business of doing it yourself.
bca-0353f40e
CC BY-SA 4.0
2022-11-21T02:15:01.330Z
Thanks for the very thorough answer.
Ryan
CC BY-SA 4.0
2022-11-20T07:48:41.063Z
2022-11-20T19:31:49.463Z
2022-11-20T19:31:49.463Z
bca-0353f40e
<p>I still don't have the full answer, and the following is only for BTC (I'd prefer an answer that works across many blockchains):</p>
<p>I found steps at <a href="https://support.ledger.com/hc/en-us/articles/6275459128989-How-to-analyze-a-Bitcoin-BTC-account-xPub?docs=true" rel="nofollow noreferrer">https://support.ledger.com/hc/en-us/articles/6275459128989-How-to-analyze-a-Bitcoin-BTC-account-xPub?docs=true</a> to be a helpful start:</p>
<ol>
<li>go to Ledger Live &gt; Accounts &gt; Bitcoin &gt; wrench icon &gt; Advanced and grab my &quot;xpub&quot; string</li>
<li>Use <a href="https://www.blockonomics.co/views/segwit_xpub_convert.html" rel="nofollow noreferrer">https://www.blockonomics.co/views/segwit_xpub_convert.html</a> to convert it to a zpub string</li>
<li>Use <a href="https://blockpath.com/" rel="nofollow noreferrer">https://blockpath.com/</a> or <a href="https://www.cointracker.io/wallet/bitcoin?address=xxxxxx" rel="nofollow noreferrer">https://www.cointracker.io/wallet/bitcoin?address=xxxxxx</a> to view the total balance.</li>
</ol>
<p>See also <a href="https://support.cointracker.io/hc/en-us/articles/4413049732625-What-is-xPub-yPub-zPub-and-UTXO-" rel="nofollow noreferrer">https://support.cointracker.io/hc/en-us/articles/4413049732625-What-is-xPub-yPub-zPub-and-UTXO-</a></p>
<p>I still have not found an API that can return the BTC total balance from a zpub address.</p>

CC BY-SA 4.0
2022-11-20T00:43:08.197Z
2022-11-20T03:08:42.373Z
2022-11-20T03:08:42.373Z
Ryan
<p>I'm new to Ledger.</p>
<p>As a software engineer, I'd like to write my own app (for my own personal use) that is sort of like a more basic version of Ledger Live.</p>
<p>I want to show my balances on my own private Google Sheet that I'm building for myself.</p>
<p>I want to use Apps Scripts to fetch totals from all of the relevant blockchains (ideally via a simple, free API) in a format like:</p>
<pre><code>{
  BTC: 0.1,
  ETH: 1,
  NEAR: 20
}
</code></pre>
<p>where each ticker shows the total (sum) of all tokens that my Ledger &quot;holds&quot;.</p>
<p>Since Bitcoin, Ethereum, and other blockchains are all public, I figured I'd easily be able to look up my wallets' balances via the public wallet addresses.</p>
<p>But now my understanding is that my Ledger's public wallet addresses for each blockchain change after transactions.</p>
<p>So how can I accomplish my goal?</p>
<p>Again, I want a simple sum of the tokens as shown in the JSON above.</p>
<p>And I want that sum to be retrievable periodically automatically without me needing to log in on my Ledger.</p>
<p>Thanks!</p>
<p>P.S. I found <a href="https://bitcoin.stackexchange.com/questions/60565/is-it-possible-to-use-xpub-address-to-monitor-balance-from-previously-generated?rq=1">Is it possible to use xpub address to monitor balance from previously generated addresses?</a> and <a href="https://bitcoin.stackexchange.com/questions/61616/how-to-know-balance-in-ledger-nano-s?rq=1">How to know balance in Ledger Nano S?</a></p>
<p>But when I go to Ledger Live &gt; Accounts &gt; Bitcoin &gt; wrench icon &gt; Advanced and grab my &quot;xpub&quot; string and go browse it at <a href="https://www.blockchain.com/btc/xpub/xxxx" rel="nofollow noreferrer">https://www.blockchain.com/btc/xpub/xxxx</a>, I see 20 wallet addresses (split across 4 pages) with 0 transactions each. So it seems like these are <em>future</em> wallets instead of the ones that my Ledger has used so far.</p>

<api><ledger-hardware-wallet>
How to retrieve total BTC held in Ledger wallet
Ryan
# How to retrieve total BTC held in Ledger wallet

(Asked by: username_0 on 2022-11-19)

I'm new to Ledger.

As a software engineer, I'd like to write my own app (for my own personal use) that is sort of like a more basic version of Ledger Live.

I want to show my balances on my own private Google Sheet that I'm building for myself.

I want to use Apps Scripts to fetch totals from all of the relevant blockchains (ideally via a simple, free API) in a format like:

```
{
  BTC: 0.1,
  ETH: 1,
  NEAR: 20
}

```

where each ticker shows the total (sum) of all tokens that my Ledger "holds".

Since Bitcoin, Ethereum, and other blockchains are all public, I figured I'd easily be able to look up my wallets' balances via the public wallet addresses.

But now my understanding is that my Ledger's public wallet addresses for each blockchain change after transactions.

So how can I accomplish my goal?

Again, I want a simple sum of the tokens as shown in the JSON above.

And I want that sum to be retrievable periodically automatically without me needing to log in on my Ledger.

Thanks!

P.S. I found [Is it possible to use xpub address to monitor balance from previously generated addresses?](https://bitcoin.stackexchange.com/questions/60565/is-it-possible-to-use-xpub-address-to-monitor-balance-from-previously-generated?rq=1) and [How to know balance in Ledger Nano S?](https://bitcoin.stackexchange.com/questions/61616/how-to-know-balance-in-ledger-nano-s?rq=1)

But when I go to Ledger Live > Accounts > Bitcoin > wrench icon > Advanced and grab my "xpub" string and go browse it at <https://www.blockchain.com/btc/xpub/xxxx>, I see 20 wallet addresses (split across 4 pages) with 0 transactions each. So it seems like these are *future* wallets instead of the ones that my Ledger has used so far.

**Tags:** api, ledger-hardware-wallet


---

## 3 answers

### Answer by username_1 on 2022-11-24. Score: 2 | Accepted answer

[Blockonomics API](https://www.blockonomics.co/views/api.html#balance) supports balance and tx history of xpub/ypub/zpub

You can use the following sites to search address balance/history of xpub/ypub/zpub :

* [Blockpath](https://blockpath.com/search/xpub?q=xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8)
* [Blockonomics](https://www.blockonomics.co/)

> **Comments:**
> **username_0**: It looks like it requires registering an email address (and maybe also paying?), which I might not be willing to do, but I will check out https://github.com/blockonomics/blockonomics-node#methods. Thanks. I'm very surprised that Ledger hasn't provided an easier way to track balances. I don't want to have to code a solution for each blockchain.  
> **username_1**: Yes email address is required for the APIKey. Its free as you long as you query withing their limits https://www.blockonomics.co/views/api.html#limits  

---

### Answer by username_2 on 2022-11-20. Score: 3

I will not repeat the mental model of how keys, addresses, and balances work on Bitcoin, let's assume you're familiar with this: <https://bitcoin.stackexchange.com/a/115830/137501>

One more thing to note about:

> I still don't have the full answer, and the following is only for BTC (I'd prefer an answer that works across many blockchains)

The answer you get for Bitcoin can only apply to other Bitcoin-tech blockchains (like Litecoin, Bitcoin Cash, etc.). Other blockchains like Ethereum use totally different schemes, which I'm not familiar with at all.

Ok, so you know that in order to find your UTXOs you need to find some good libraries that implement these 3 BIPs:

* [BIP32 Hierarchical Deterministic Wallets](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki)
* [BIP39 Mnemonic code for generating deterministic keys](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki)
* [BIP44 Multi-Account Hierarchy for Deterministic Wallets](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki)

Also, SatoshiLabs (Trezor wallet manufacturer) maintains a list of derivation paths for many blockchains:

* [SLIP-0044 : Registered coin types for BIP-0044](https://github.com/satoshilabs/slips/blob/master/slip-0044.md)

On a higher level, you have to:

1. Generate the master key from mnemonic
2. Generate the master xpub. Note that generating the master key and the xpub should be done on an offline device, and then copied over to the online device to preserve security of "air-gapping". Maybe the Ledger device can export just the xpub? If that's possible then you can skip the risky business of doing it yourself.
3. Use the derivation path to produce a list of some `N` addresses
4. Scan the UTXO set against those addresses and tally the balance
5. If you want the wallet history and not just the current balance, you need to scan the entire blockchain against the list of addresses

Note that wallets make a new address each time you receive payment, so the list will grow.
When you're restoring a wallet from seed they don't know the `N`, so what they do is they scan for some number of addresses, like 100, and then find the last address that was actually used, and then scan for 100 more from that one, until they get to the 100 which was never used.

So, how to do the scanning in steps 4. and 5.?
I'm not fully familiar with that but I can tell you where to look:

1. If you're running your own node, find the [node's RPC documentation](https://developer.bitcoin.org/reference/rpc/), and see if you can get most of the job done using the node's RPC
2. Use [Electrum APIs](https://electrumx-spesmilo.readthedocs.io/en/latest/protocol.html) to get what you need, either from a public server of from running your own Electrum server alongside your node.
3. Use Ledger APIs and talk to their servers the same way their wallet talks to them, but I'm not sure how well this is documented.

With 2., there are plenty of public servers you could query, and the data can be verified in a [trustless manner](https://bitcoin.stackexchange.com/a/115974/137501), all you need are block headers.
However, the server may store your queries and IPs so there's a privacy loss trade-off.
If you don't want to use a server, you can run an [Electrum server](https://github.com/cculianu/Fulcrum) by yourself alongside your node, and the server will produce indexes from the blockchain data so an address history can be easily looked up.

> **Comments:**
> **username_3**: There's lots to like in this answer (upvoted) but it might be worth mentioning that extracting private keys from a hardware wallet and using them in a general purpose PC has significant security drawbacks.  
> **username_2**: Thanks, added a little note next to step 2: Note that generating the master key and the xpub should be done on an offline device, and then copied over to the online device to preserve security of "air-gapping". Maybe the Ledger device can export just the xpub? If that's possible then you can skip the risky business of doing it yourself.  
> **username_0**: Thanks for the very thorough answer.  

---

### Answer by username_0 on 2022-11-20. Score: 2

I still don't have the full answer, and the following is only for BTC (I'd prefer an answer that works across many blockchains):

I found steps at <https://support.ledger.com/hc/en-us/articles/6275459128989-How-to-analyze-a-Bitcoin-BTC-account-xPub?docs=true> to be a helpful start:

1. go to Ledger Live > Accounts > Bitcoin > wrench icon > Advanced and grab my "xpub" string
2. Use <https://www.blockonomics.co/views/segwit_xpub_convert.html> to convert it to a zpub string
3. Use <https://blockpath.com/> or <https://www.cointracker.io/wallet/bitcoin?address=xxxxxx> to view the total balance.

See also <https://support.cointracker.io/hc/en-us/articles/4413049732625-What-is-xPub-yPub-zPub-and-UTXO->

I still have not found an API that can return the BTC total balance from a zpub address.


---

