Author

Topic: Show balance of BTC using PHP question (Read 472 times)

hero member
Activity: 490
Merit: 500
37iGtdUJc2xXTDkw5TQZJQX1Wb98gSLYVP
April 27, 2015, 10:12:44 AM
#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 "
". $con_bal;



thank you so much for helping me Cheesy
legendary
Activity: 1442
Merit: 1186
April 27, 2015, 07:49:06 AM
#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 "
". $con_bal;

hero member
Activity: 490
Merit: 500
37iGtdUJc2xXTDkw5TQZJQX1Wb98gSLYVP
April 27, 2015, 07:32:25 AM
#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
Jump to: