4

I am a complete noob to PHP. But I just wanted to know how can you use the BlockChain API to get your wallet balance. I tried but could get no result. I do not even know how to print it. Please help. This is my current code :-

    <?php

    $guid="xxxxxxxxx";
    $main_password="xxxxxxxxx";

    $json_url = "https://blockchain.info/merchant/$guid/balance?password=$main_password";

    $json_data = file_get_contents($json_url);

    $json_feed = json_decode($json_data);

    $message = $json_feed->message;

    ?>

And what exactly is the guid? Is it the wallet identifier?

4

Your code is close to what you need:

<?php

$guid="xxxxxxxxx";
$main_password="xxxxxxxxx";

$json_url = "https://blockchain.info/merchant/$guid/balance?password=$main_password";

$json_data = file_get_contents($json_url);

$json_feed = json_decode($json_data);

$balance = $json_feed->balance;

echo $balance;
?>

The response looks like this (Wallet Balance in Satoshi):

{ "balance": 1000}

So you need to fetch the balance object not the message one. Then add an echo to print out the balance.

  • balance; echo $balance; ?> this is the result I got. Don't know why. – rahulgarg12342 Jul 18 '14 at 19:24
  • just tested it with my own wallet it worked perfectly fine, maybe your put in the wrong credentials – Dennis Kriechel Jul 18 '14 at 19:27
  • is the guid the wallet identifier? – rahulgarg12342 Jul 18 '14 at 19:28
  • yes its is, maybe you missed out a semicolon or an php tag, seems like an syntax error in your php maybe try to copy paste again – Dennis Kriechel Jul 18 '14 at 19:28
  • ahh got it. The 2 factor auth was messing it up. Figured it out. Thanks. Just a little curious. How could I modify this to be performed after a certain time interval? – rahulgarg12342 Jul 18 '14 at 19:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.