Bitcoin Forum
June 24, 2024, 04:27:25 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Show balance of BTC using PHP question  (Read 453 times)
thebenjamincode (OP)
Hero Member
*****
Offline Offline

Activity: 490
Merit: 500


37iGtdUJc2xXTDkw5TQZJQX1Wb98gSLYVP


View Profile
April 27, 2015, 12:32:25 PM
 #1

hi there everyone, i am new to programming using api
does anyone here can share a code about showing the balance of a btc address using php?

please give me the code because i can't understand the api
thank you! Cheesy
coinableS
Legendary
*
Offline Offline

Activity: 1442
Merit: 1180



View Profile WWW
April 27, 2015, 12:49:06 PM
 #2

You can do this easily with blockchain.info's API.

Checkout their documentation and scroll down to "Single Address": https://blockchain.info/api/blockchain_api
 
https://blockchain.info/address/$bitcoin_address?format=json

Using this you can get the balance in JSON format and parse it with PHP.

Code:
//Declare an address as a variable
$btc_address = "1J9ikqFuwrzPbczsDkquA9uVYeq6dEehsj";

//Get the balance using blockchaininfo API
$addr_url = "https://blockchain.info/address/$btc_address?format=json";
$json_addr = json_decode(file_get_contents($addr_url), true);
$balance = $json_addr["final_balance"];

//Display the balance on the screen in satoshis
echo $balance;

//Display on the screen as bitcoins
$con_bal = $balance / 100000000;
echo "<br>". $con_bal;


thebenjamincode (OP)
Hero Member
*****
Offline Offline

Activity: 490
Merit: 500


37iGtdUJc2xXTDkw5TQZJQX1Wb98gSLYVP


View Profile
April 27, 2015, 03:12:44 PM
 #3

You can do this easily with blockchain.info's API.

Checkout their documentation and scroll down to "Single Address": https://blockchain.info/api/blockchain_api
 
https://blockchain.info/address/$bitcoin_address?format=json

Using this you can get the balance in JSON format and parse it with PHP.

Code:
//Declare an address as a variable
$btc_address = "1J9ikqFuwrzPbczsDkquA9uVYeq6dEehsj";

//Get the balance using blockchaininfo API
$addr_url = "https://blockchain.info/address/$btc_address?format=json";
$json_addr = json_decode(file_get_contents($addr_url), true);
$balance = $json_addr["final_balance"];

//Display the balance on the screen in satoshis
echo $balance;

//Display on the screen as bitcoins
$con_bal = $balance / 100000000;
echo "<br>". $con_bal;



thank you so much for helping me Cheesy
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!