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?

rahulgarg12342
  • 247
  • 1
  • 5
  • 10

1 Answers1

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.

Dennis Kriechel
  • 1,763
  • 4
  • 16
  • 34
  • 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
  • @rahulgarg12342 How did you bypass the 2 factor authenticator? I am using the block chain api to do exactly the same thing, it is working but for 2 factor authenticator enabled wallets I am getting the error. How do I deal with that? – Criesto Sep 04 '14 at 08:23