Author

Topic: Getting number of bitcoins associated to bitcoin address/public key (Read 260 times)

HCP
legendary
Activity: 2086
Merit: 4363
Yes it is possible to do that... but you'd probably be reinventing the wheel... there are already blockfile parsers available: https://github.com/alecalve/python-bitcoin-blockchain-parser


And yes, it is highly likely that the big block explorers like b.info, blockcypher, blockchair etc all have custom databases where they store indexed data that they have parsed from the blockchain data.
newbie
Activity: 25
Merit: 10
There is no direct RPC call built into Bitcoin Core that you can use to say "give me the balance of any given address". You would need to build your own bespoke database, derived from blockchain data that you could then query using your block explorer. Something similar to this open-source block explorer: https://github.com/iquidus/explorer

You'll see it has a "sync" module which parses transaction data and updates local database files.

It also requires that your node is running with the txindex=1 option enabled (either on commandline or in bitcoin.conf) so that all transactions are indexed and not just ones that are related to your own wallet addresses.

I think this is the kind of thing I am looking for, but even more low level.  As in, is it possible to extract the data stored in each block and save the addresses and balances in a custom database, in order to perform fast searches later based on address to output the balance?  Wondering if blockchain.info does something similar?
newbie
Activity: 25
Merit: 10
You mean the balance? If so, you can't check that for an address that is not yours. See this[1][2].

I have tried using some of the existing 3rd party API's but those are either too close or expensive or both, so was thinking about creating something myself locally.

I'm not sure what do you mean by "too close" but there are a lot of APIs that provide that functionality for free (Blockchair, Blockonomics, BTC.com, etc.). Which APIs have you tried so far?

[1] https://bitcoin.stackexchange.com/questions/59237/determine-address-balance-using-bitcoin-core
[2] https://bitcoin.stackexchange.com/questions/58242/how-to-get-balance-by-any-address-using-rpc-bitcoind

Sorry, I've now clarified my question above.
HCP
legendary
Activity: 2086
Merit: 4363
There is no direct RPC call built into Bitcoin Core that you can use to say "give me the balance of any given address". You would need to build your own bespoke database, derived from blockchain data that you could then query using your block explorer. Something similar to this open-source block explorer: https://github.com/iquidus/explorer

You'll see it has a "sync" module which parses transaction data and updates local database files.

It also requires that your node is running with the txindex=1 option enabled (either on commandline or in bitcoin.conf) so that all transactions are indexed and not just ones that are related to your own wallet addresses.
legendary
Activity: 2352
Merit: 6089
bitcoindata.science
Hello

I have done this is excel using blockchair API data.

https://bitcointalksearch.org/topic/create-an-address-and-wallet-watcher-for-free-with-excel-blockchair-api-5245623
...
1 - Download Excel Power Query https://www.microsoft.com/en-us/download/details.aspx?id=39379&CorrelationId=c9c9ec0d-5336-4ba8-a6a7-7b229fb861ac

2 - Click Add Data From Web


3 - On the URL enter:

https://api.blockchair.com/bitcoin/dashboards/addresses/{:address}
{:address} = (for a set of up to 100 addresses, comma-separated, further referred to as the addresses dashboard)
(source=https://blockchair.com/api/docs)

4- Once API data shows up, click in Data > Record.
Then click Set > Record

5 - Then click convert Into Table

...


The user    Coding Enthusiast did that in C.

https://bitcointalksearch.org/topic/c-watch-only-bitcoin-wallet-support-segwit-and-forks-v31-1616888

....
Introduction
This is a simple open source tool which can help users keep track of their bitcoin addresses, balance of each address, bitcoin price and Total balance value in BTC, $ and user's local currency, balances at a specific height.
The main focus will be in keeping this tool light and fast.



*Click on the image to see bigger size*

...

There is also the website http://www.homebitcoin.com/easybalance/ which does that but it doesn't support segwit addresses.


Maybe those projects can help you in your project. I don't know how to use your local bitcoin core RPC api, but I believe it should be easy.

You can click in those respective threads for more details, I just quoted a small part of each.
staff
Activity: 3500
Merit: 6152
You mean the balance? If so, you can't check that for an address that is not yours. See this[1][2].

I have tried using some of the existing 3rd party API's but those are either too close or expensive or both, so was thinking about creating something myself locally.

I'm not sure what do you mean by "too close" but there are a lot of APIs that provide that functionality for free (Blockchair, Blockonomics, BTC.com, etc.). Which APIs have you tried so far?

[1] https://bitcoin.stackexchange.com/questions/59237/determine-address-balance-using-bitcoin-core
[2] https://bitcoin.stackexchange.com/questions/58242/how-to-get-balance-by-any-address-using-rpc-bitcoind
newbie
Activity: 25
Merit: 10
Is it possible to use bitcoin-core's RPC api (assuming the full blockchain is downloaded locally) to type in any public bitcoin address and get back the balance?  I am wanting to learn more by trying to create a website similar to blockchain.info where people can simply type in a bitcoin address and see how much bitcoin is associated with that address/key.

I have tried using some of the existing 3rd party API's but those are either too slow or expensive or both, so was thinking about creating something myself locally.

So I guess my question is, how do websites like blockchain.info index the blockchain and get the balance of any given bitcoin address, so it can be stored in a custom database for fast searching?
Jump to: