Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: Samudda on September 10, 2014, 09:47:05 AM



Title: How to get the information about a bitcoin address without 3rd-pard services?
Post by: Samudda on September 10, 2014, 09:47:05 AM
I have a bitcoin address. How do I get it's balance and the amount of BTC it's ever sent and received? I don't want to use any third-party bitcoin services, I want to do it as directly as possible. How can I do that?


Title: Re: How to get the information about a bitcoin address without 3rd-pard services?
Post by: RustyNomad on September 10, 2014, 11:14:50 AM
You will have to use a third party or a wallet AFAIK.

Easiest is to go to blockchain.info and just paste the address in the search at the top. That will pull all the history from the block chain for you and will give you a summary of the transactions on that address.


Title: Re: How to get the information about a bitcoin address without 3rd-pard services?
Post by: deepceleron on September 10, 2014, 11:37:22 AM
http://bitcoin.stackexchange.com/questions/10090/how-to-get-an-addresss-balance-with-the-bitcoin-client

If you don't want to use a third-party service, you can use third-party software on your own Bitcoin:
https://en.bitcoin.it/wiki/Abe
https://insight.bitpay.com/



Title: Re: How to get the information about a bitcoin address without 3rd-pard services?
Post by: amaclin on September 10, 2014, 11:38:04 AM
You should code something like this:

Code:
long balance = 0;
for ( int i = 0; !atEnd ( ); i++ )
{
  Block b = getBlock ( i );
  for ( int j = 0; j < b.txCount ( ); j++ )
  {
    Transaction tx = b.getTransaction ( j );
    for ( int k = 0; k < tx.countOutputs ( ); k++ )
    {
       Output out = tx.getOutput ( k );
       if ( out.isMyIncoming ( ) )
         balance += out.getAmount ( );
    }
    for ( int k = 0; k < tx.countInputs ( ); k++ )
    {
       Input in = tx.getInput ( k );
       if ( in.isMyOutgoing ( ) )
         balance -= in.getAmount ( );
    }
  }
}


Title: Re: How to get the information about a bitcoin address without 3rd-pard services?
Post by: andytoshi on September 10, 2014, 11:55:27 AM
Addresses do not send funds. This is a dangerous misconception covered on the wiki (https://en.bitcoin.it/wiki/From_address).


Title: Re: How to get the information about a bitcoin address without 3rd-pard services?
Post by: Samudda on September 10, 2014, 12:36:32 PM
No third-party services! Why would I do that through a third-party service if I can do that without it? After all, how those third-party services do that? They use the standard way. So I want to find out what this way is and use it too.

You should code something like this:

Code:
long balance = 0;
for ( int i = 0; !atEnd ( ); i++ )
......
}

That doesn't make sense. If what language is this? How can I run it?


Title: Re: How to get the information about a bitcoin address without 3rd-pard services?
Post by: amaclin on September 10, 2014, 12:47:17 PM
Quote
That doesn't make sense. If what language is this? How can I run it?

Sorry. It is too difficult for me to explain things in good English.
I mean that you should parse blockchain (.blk-files), take each block, parse it, take each transaction, parse inputs and outputs.
Of course, my code is not "real code". You should write parser yourself or ask somebody to do it.
May be it is also possible to find "exactly-what-you-want-program" in the Internet.


Title: Re: How to get the information about a bitcoin address without 3rd-pard services?
Post by: Samudda on September 10, 2014, 01:27:21 PM
http://bitcoin.stackexchange.com/questions/10090/how-to-get-an-addresss-balance-with-the-bitcoin-client

If you don't want to use a third-party service, you can use third-party software on your own Bitcoin:
https://en.bitcoin.it/wiki/Abe
https://insight.bitpay.com/



service or software, what's the difference? The bottom line is that I don't want to use anything third-party.


Thanks for the link but since I'm quite a newbie I'd like more through information.


Title: Re: How to get the information about a bitcoin address without 3rd-pard services?
Post by: Muhammed Zakir on September 10, 2014, 01:50:22 PM
You can get some API for for transactions of an address here : https://blockchain.info/api/blockchain_api . Do 'third party' includes blockexplorer and wallets?

  ~~MZ~~


Title: Re: How to get the information about a bitcoin address without 3rd-pard services?
Post by: Samudda on September 10, 2014, 01:55:28 PM
You can get some API for for transactions of an address here : https://blockchain.info/api/blockchain_api . Do 'third party' includes blockexplorer and wallets?

  ~~MZ~~

Third-party includes any website because protocol bitcoin doesn't have a central web site. Blockchain is also a third-party web site.


Title: Re: How to get the information about a bitcoin address without 3rd-pard services?
Post by: Samudda on September 10, 2014, 02:08:20 PM
You will have to use a third party or a wallet AFAIK.

Easiest is to go to blockchain.info and just paste the address in the search at the top. That will pull all the history from the block chain for you and will give you a summary of the transactions on that address.
Have to? You're wrong.

blockchain.info obtains that information from somewhere, not from other web site.


Title: Re: How to get the information about a bitcoin address without 3rd-pard services?
Post by: deepceleron on September 10, 2014, 02:08:37 PM
The question was already answered if attention was paid. Bitcoin won't do it without help. Get ABE open blockchain explorer and install it to work with your own bitcoin, then you can just type the addresses into your own web page once it is indexed.


Title: Re: How to get the information about a bitcoin address without 3rd-pard services?
Post by: Samudda on September 10, 2014, 02:18:35 PM
No, it wasn't unanswered.

"just type the addresses into your own web page once it is indexed." - I don't want to type an address. I want to create such a program myself. Is that more clear?



Title: Re: How to get the information about a bitcoin address without 3rd-pard services?
Post by: amaclin on September 10, 2014, 03:01:27 PM
Quote
I want to create such a program myself. Is that more clear?

What will be your programming language?


Title: Re: How to get the information about a bitcoin address without 3rd-pard services?
Post by: keeshux on September 10, 2014, 03:58:00 PM
You'll be only able to get such information about an address if you have a full node history locally. Given that, the overall process is:

  • Parse blocks from files
  • For each block, iterate through all transactions
  • For each transaction, parse output scripts
  • If the output script is of some standard form, you can get an address out of its bytes
  • If the parsed address matches the one you're interested in, add the transaction to your "interesting" set
  • From the relevant transactions you can finally infer all the stats you need, e.g. balance, sent/received..

This is just a generic slow algorithm because I don't know the structure of Bitcoin Core files. Some existing index would surely improve search efficiency (e.g. the UTXO index is enough for the balance), in fact web providers must have some internal index on addresses. I've seen many tools around that build fast databases from raw blocks, but I've never used them.

If you don't have any local history, the only way I'm aware of is loading a Bloom filter matching your address and scan the whole blockchain. The peers will then send you relevant transactions for that address plus some unrelevant ones due to the probabilistc nature of the Bloom filter. Beware that you will be forced to do a full rescan for each new address you want to search.


Title: Re: How to get the information about a bitcoin address without 3rd-pard services?
Post by: amaclin on September 10, 2014, 04:08:54 PM
Quote
This is just a generic slow algorithm because I don't know the structure of Bitcoin Core files.

1) It is not very slow, because you should not verify signatures (your bitcoind did it)
2) Bitcoin core files have very simple structure. Have a look here
https://bitcointalk.org/index.php?topic=762445.msg8623440#msg8623440


Title: Re: How to get the information about a bitcoin address without 3rd-pard services?
Post by: keeshux on September 10, 2014, 04:17:22 PM
Quote
This is just a generic slow algorithm because I don't know the structure of Bitcoin Core files.

1) It is not very slow, because you should not verify signatures (your bitcoind did it)
2) Bitcoin core files have very simple structure. Have a look here
https://bitcointalk.org/index.php?topic=762445.msg8623440#msg8623440


Not intrinsically slow, probably slow when run on 20GB of unindexed data..


Title: Re: How to get the information about a bitcoin address without 3rd-pard services?
Post by: amaclin on September 10, 2014, 04:29:08 PM
Quote
Not intrinsically slow, probably slow when run on 20GB of unindexed data..

something  x2...x3 times slower than just copying 20gb of data


Title: Re: How to get the information about a bitcoin address without 3rd-pard services?
Post by: Buffer Overflow on September 10, 2014, 06:28:46 PM
No, it wasn't unanswered.

"just type the addresses into your own web page once it is indexed." - I don't want to type an address. I want to create such a program myself. Is that more clear?



Then you need to have a full bitcoin node running locally. The program your planning to make will need to query the node's database to find the transactions your looking for.

This has been done already. Unless your after some programming practise, why reinvent the wheel?


Title: Re: How to get the information about a bitcoin address without 3rd-pard services?
Post by: keeshux on September 10, 2014, 06:50:26 PM
Quote
Not intrinsically slow, probably slow when run on 20GB of unindexed data..

something  x2...x3 times slower than just copying 20gb of data

I would consider "slow" a database query that takes that much. :) That's why a nice indexed structure is a huge advantage and several tools certainly exist to build an efficient blockchain database and execute fast queries on top of it. Unless it's about practicing, as Buffer Overflow pointed out.