I would like to get the balance of a Bitcoin address at a particular block number or date.
Is there any way to retrieve this data from JSON-RPC? Alternatively, is there any API or blockchain analytics service that provides this? Thanks.
Bitcoin Stack Exchange is a question and answer site for Bitcoin crypto-currency enthusiasts. It only takes a minute to sign up.
Sign up to join this communityI would like to get the balance of a Bitcoin address at a particular block number or date.
Is there any way to retrieve this data from JSON-RPC? Alternatively, is there any API or blockchain analytics service that provides this? Thanks.
Account/address balance are higher level constructs that are built on Bitcoin's low-level transaction scripting language and cryptography. As such, data related to funds 'belonging' to a particular address is not readily available in the blockchain, but has to be built separately by scanning the entire database. The Bitcoin-Core reference client does not even support showing 'balances' of address that are not part of your wallet, let alone providing you the data related to a particular address at a particular point in time. You would either have to do this yourself or search for third-party data providers who provide this kind of information through an API (that is off-topic on this forum).
That's rather complicated as "balance" is an higher order construct which exists only at wallet application level.
This means that you need to do some substancial coding.
Anyway, you could approach the problem this way:
1) convert the desired point in time to block height
2) query the blockchain by address. You can easily do that using blockchain.info API
https://blockchain.info/multiaddr?active=$address|$address
the API will return also a list of transactions received/sent by a given address.
3) loop through the transaction list to figure if relevant outputs (UTXOs) ware received and unspent at a given point in time. You can do that by referencing the transaction block height provided by the API after having mapped incoming (received) and outgoing (sent) TXs by cross-referencing TX hashes.
I have written a program in Python3 that allows you to search for any address on bitcoin core whether it belongs to your wallet or not.
Here is the github link:
https://github.com/ORP967/Bitcoin_Core_RPC_par_address
Let me know what you think or if you have any improvements you might have.