Bitcoin Forum
November 04, 2024, 04:15:30 AM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Getting number of bitcoins associated to bitcoin address/public key  (Read 253 times)
oshirowanen (OP)
Newbie
*
Offline Offline

Activity: 25
Merit: 10


View Profile
June 03, 2020, 03:17:59 PM
Last edit: June 04, 2020, 08:54:13 AM by oshirowanen
Merited by LoyceV (6), OmegaStarScream (1), bitmover (1), o_e_l_e_o (1)
 #1

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?
OmegaStarScream
Staff
Legendary
*
Offline Offline

Activity: 3654
Merit: 6409



View Profile
June 03, 2020, 03:24:51 PM
 #2

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

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
bitmover
Legendary
*
Offline Offline

Activity: 2478
Merit: 6286


bitcoindata.science


View Profile WWW
June 03, 2020, 03:26:42 PM
 #3

Hello

I have done this is excel using blockchair API data.

https://bitcointalk.org/index.php?topic=5245623.0
...
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://bitcointalk.org/index.php?topic=1616888.0

....
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.

HCP
Legendary
*
Offline Offline

Activity: 2086
Merit: 4361

<insert witty quote here>


View Profile
June 03, 2020, 09:02:53 PM
 #4

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.

█████████████████████████
████▐██▄█████████████████
████▐██████▄▄▄███████████
████▐████▄█████▄▄████████
████▐█████▀▀▀▀▀███▄██████
████▐███▀████████████████
████▐█████████▄█████▌████
████▐██▌█████▀██████▌████
████▐██████████▀████▌████
█████▀███▄█████▄███▀█████
███████▀█████████▀███████
██████████▀███▀██████████
█████████████████████████
.
BC.GAME
▄▄░░░▄▀▀▄████████
▄▄▄
██████████████
█████░░▄▄▄▄████████
▄▄▄▄▄▄▄▄▄██▄██████▄▄▄▄████
▄███▄█▄▄██████████▄████▄████
███████████████████████████▀███
▀████▄██▄██▄░░░░▄████████████
▀▀▀█████▄▄▄███████████▀██
███████████████████▀██
███████████████████▄██
▄███████████████████▄██
█████████████████████▀██
██████████████████████▄
.
..CASINO....SPORTS....RACING..
█░░░░░░█░░░░░░█
▀███▀░░▀███▀░░▀███▀
▀░▀░░░░▀░▀░░░░▀░▀
░░░░░░░░░░░░
▀██████████
░░░░░███░░░░
░░█░░░███▄█░░░
░░██▌░░███░▀░░██▌
░█░██░░███░░░█░██
░█▀▀▀█▌░███░░█▀▀▀█▌
▄█▄░░░██▄███▄█▄░░▄██▄
▄███▄
░░░░▀██▄▀


▄▄████▄▄
▄███▀▀███▄
██████████
▀███▄░▄██▀
▄▄████▄▄░▀█▀▄██▀▄▄████▄▄
▄███▀▀▀████▄▄██▀▄███▀▀███▄
███████▄▄▀▀████▄▄▀▀███████
▀███▄▄███▀░░░▀▀████▄▄▄███▀
▀▀████▀▀████████▀▀████▀▀
oshirowanen (OP)
Newbie
*
Offline Offline

Activity: 25
Merit: 10


View Profile
June 04, 2020, 08:54:37 AM
 #5

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.
oshirowanen (OP)
Newbie
*
Offline Offline

Activity: 25
Merit: 10


View Profile
June 04, 2020, 08:58:49 AM
 #6

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?
HCP
Legendary
*
Offline Offline

Activity: 2086
Merit: 4361

<insert witty quote here>


View Profile
June 04, 2020, 09:25:51 AM
 #7

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.

█████████████████████████
████▐██▄█████████████████
████▐██████▄▄▄███████████
████▐████▄█████▄▄████████
████▐█████▀▀▀▀▀███▄██████
████▐███▀████████████████
████▐█████████▄█████▌████
████▐██▌█████▀██████▌████
████▐██████████▀████▌████
█████▀███▄█████▄███▀█████
███████▀█████████▀███████
██████████▀███▀██████████
█████████████████████████
.
BC.GAME
▄▄░░░▄▀▀▄████████
▄▄▄
██████████████
█████░░▄▄▄▄████████
▄▄▄▄▄▄▄▄▄██▄██████▄▄▄▄████
▄███▄█▄▄██████████▄████▄████
███████████████████████████▀███
▀████▄██▄██▄░░░░▄████████████
▀▀▀█████▄▄▄███████████▀██
███████████████████▀██
███████████████████▄██
▄███████████████████▄██
█████████████████████▀██
██████████████████████▄
.
..CASINO....SPORTS....RACING..
█░░░░░░█░░░░░░█
▀███▀░░▀███▀░░▀███▀
▀░▀░░░░▀░▀░░░░▀░▀
░░░░░░░░░░░░
▀██████████
░░░░░███░░░░
░░█░░░███▄█░░░
░░██▌░░███░▀░░██▌
░█░██░░███░░░█░██
░█▀▀▀█▌░███░░█▀▀▀█▌
▄█▄░░░██▄███▄█▄░░▄██▄
▄███▄
░░░░▀██▄▀


▄▄████▄▄
▄███▀▀███▄
██████████
▀███▄░▄██▀
▄▄████▄▄░▀█▀▄██▀▄▄████▄▄
▄███▀▀▀████▄▄██▀▄███▀▀███▄
███████▄▄▀▀████▄▄▀▀███████
▀███▄▄███▀░░░▀▀████▄▄▄███▀
▀▀████▀▀████████▀▀████▀▀
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!