Bitcoin Forum

Bitcoin => Bitcoin Discussion => Topic started by: jtimon on April 23, 2011, 03:43:26 PM



Title: total received counter for donations
Post by: jtimon on April 23, 2011, 03:43:26 PM
Is there some javascript or something that you can add to your web and contains the following?

-bitcoin address to send donations
-Total amount of bitcoins sent to that address (It doesn't matter if they're gone).
-Total amount of bitcoins needed (optional)

I think it could be useful for some projects or pledges.


Title: Re: total received counter for donations
Post by: Alex Beckenham on April 23, 2011, 03:52:36 PM
Can you run PHP on the same site?


Title: Re: total received counter for donations
Post by: jtimon on April 23, 2011, 03:57:43 PM
I don't have a site. Just asking. Is there something like that for php?


Title: Re: total received counter for donations
Post by: Alex Beckenham on April 23, 2011, 04:12:42 PM
Well, there is now... sort of.

I just put together this very nasty, barely tested bit of PHP to scrape the blockexplorer site for a given address's total received amount.

Code:
<?php

$donation_address
=$_GET['addr'];

$ch curl_init('http://blockexplorer.com/address/'.$donation_address);
curl_setopt ($chCURLOPT_RETURNTRANSFER1) ;
$html curl_exec($ch);
$html=substr($html,strpos($html,'Received BTC:')+14);
$btc=substr($html,0,strpos($html,'</li>'));

echo 
$btc;

die();

?>


If you save that on your site as totalbtc.php and give it an address like this:

totalbtc.php?addr=fivjiwejefijwiejwiejiwei

Then it will output the total received of that address.

As I said though, the above is downright crap code, just put together in the last few minutes... version 0.0.00.1a

Thought it might help get the ball rolling for other people's ideas anyway.



Title: Re: total received counter for donations
Post by: jtimon on April 23, 2011, 04:23:08 PM
Cool. It seems easier than I thought.


Title: Re: total received counter for donations
Post by: Alex Beckenham on April 23, 2011, 04:29:52 PM
Forgot the disclaimer:

The above code is for example purposes only. It may contain huge security flaws and may cause your server to physically explode.


Anyway,  if noone else has a shot at it, I'll try to rewrite it at some point, and add some javascript/ajax to the mix.

It's a cool idea for a widget anyway, cheers.



Title: Re: total received counter for donations
Post by: theymos on April 24, 2011, 02:34:17 AM
There's an API page for that:
http://blockexplorer.com/q/getreceivedbyaddress

I don't recommend scraping the HTML pages.


Title: Re: total received counter for donations
Post by: Alex Beckenham on April 24, 2011, 02:46:34 AM
There's an API page for that:
http://blockexplorer.com/q/getreceivedbyaddress

I don't recommend scraping the HTML pages.

Neither do I.

Thanks for the API link; I searched Google unsuccessfully for blockexplorer API but that's as far as I went.

Update:

Code:
<?php

$donation_address
=$_GET['addr'];

$ch curl_init('http://blockexplorer.com/q/getreceivedbyaddress/'.$donation_address);
curl_setopt ($chCURLOPT_RETURNTRANSFER1) ;
$btc curl_exec($ch);

echo 
$btc;

die();

?>