3

I'm using Coinbase, but they don't have an API call to get the amount of Bitcoins per address, but only per account, which is a collection of addresses.

Does anyone have an API call for this? I'd prefer to not to reinvent the wheel by setting up my own Bitcoin server/daemon as suggested in this other SO thread:

How to check Bitcoin address balance from my application?

Community
  • 1
  • 1
tim peterson
  • 23,653
  • 59
  • 177
  • 299

2 Answers2

8

Hmm, would this work for you:

<?php
function getBalance($address) {
    return file_get_contents('https://blockchain.info/q/addressbalance/'. $address);
}

echo 'Address Balance: ' . getBalance('1EzwoHtiXB4iFwedPr49iywjZn2nnekhoj');

Using the https://blockchain.info/q API.

Jens A. Koch
  • 39,862
  • 13
  • 113
  • 141
0

If you are checking the balance of a Coinbase address, you may not get the expected results because Coinbase shuffles your bitcoin around to different addresses internally. The only way to get the true balance is by account.

<?php
$accountId = '<Account Id>';
$account = $client->getAccount($accountId);
$balance = $account->getBalance();
$btc = $balance->getAmount();