1

I tried below code and gave valid credentials, but we could not get the response of balance check. What would be the solution?

<?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;
  • 1
    It would be helpfull if you showed us the response blockchain gives – Web Weave Jul 28 '16 at 12:01
  • He will receive no response since he's using an old deprecated version of their wallet service. See my response posted below. – m1xolyd1an Jul 29 '16 at 0:34
1

You are using the old, version 1, blockchain wallet API which was deprecated earlier this year. None of the calls you are trying will work.

The new, version 2, API requires you to run a local nodeJS service to handle the calls. This will require you to have root access to your webserver so you will need to use a VPS instead of a basic shared web host.

You will need to request an API key here https://blockchain.info/api/api_create_code

Install nodeJS
Install NPM
Install blockchain-wallet npm install -g blockchain-wallet-service
It should install to usr/local/bin
Run the service node blockchain-wallet-service start --port 3030
Now it's running, but you still need to complete the handshake with blockchain's server. We can do that with a cURL request in a PHP file.

some_file.php

//replace with your GUID, password and API key
 $url = "http://127.0.0.1:3030/merchant/YOUR-GUID/login?password=YOUR-PASSWORD&api_code=YOUR-API-CODE";
 $ch = curl_init();
 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 curl_setopt($ch, CURLOPT_URL, $url);
 $ccc = curl_exec($ch);
 $json = json_decode($ccc, true);
 var_dump($json);

Save the above and run it on your server. The file should keep spinning and loading since blockchain doesn't recognize the IP address. Wait for it to timeout about 60 seconds, and then check your email. Blockchain should have sent you an API access attempt showing what IP tried to connect. Follow the link and authorize the attempt, also the IP address from the email and whitelist it in your wallet account settings.

Now try running the file again. If you did everything correctly you should see a response that lists your GUID followed by Success TRUE

Now you're connected and you can start sending requests with your wallet.

Check their API documentation for example calls once you're set up. https://blockchain.info/api/blockchain_wallet_api

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.