user36024: 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? and How to know balance in Ledger Nano S?
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.

user36024: 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:

go to Ledger Live > Accounts > Bitcoin > wrench icon > Advanced and grab my "xpub" string
Use https://www.blockonomics.co/views/segwit_xpub_convert.html to convert it to a zpub string
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.

user26481: Blockonomics API 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
Blockonomics


user137501: 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
BIP39 Mnemonic code for generating deterministic keys
BIP44 Multi-Account Hierarchy for Deterministic Wallets

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

SLIP-0044 : Registered coin types for BIP-0044

On a higher level, you have to:

Generate the master key from mnemonic
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.
Use the derivation path to produce a list of some N addresses
Scan the UTXO set against those addresses and tally the balance
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:

If you're running your own node, find the node's RPC documentation, and see if you can get most of the job done using the node's RPC
Use Electrum APIs to get what you need, either from a public server of from running your own Electrum server alongside your node.
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, 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 by yourself alongside your node, and the server will produce indexes from the blockchain data so an address history can be easily looked up.

36024: <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>
 36024: <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>
 26481: <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>
 137501: <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>
