var dump of a JSON response returns NULL

0 votes

I'm writing a script to accept Bitcoin payments. My $json variable returns null. var_dump() returns NULL.

I am using the following code:

 $receiving_address = BITCOIN_ADDRESS;
    if(get_magic_quotes_gpc()){
        $callback_url = urlencode(stripslashes(CALLBACK_URL));
    }  else {
        $callback_url = urlencode(CALLBACK_URL);
    }

    $ch = curl_init("https://blockchain.info/api/receive?method=create&address=$receiving_address&shared=false&callback=$callback_url");
    curl_setopt($ch, CURLOPT_PROXY, '127.0.0.1:8888');
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $json=json_decode(curl_exec($ch),true);

    var_dump($json);
    echo $json[0]->text;
Aug 28, 2018 in Blockchain by slayer
• 29,370 points
3,415 views

1 answer to this question.

0 votes

You should be aware of the chances that some code might not execute properly. Try the following code:

$response = curl_exec($ch);
if ($result === FALSE) {
   die("Curl failed with error: " . curl_error($ch));
}
$json = json_decode($response, true);
if (is_null($json)) {
   die("Json decoding failed with error: ". json_last_error());
}
answered Aug 28, 2018 by digger
• 26,740 points

Related Questions In Blockchain

0 votes
1 answer

how loop through a JSON Array of bitcoin transaction data

for($i=0; $i<count($result['out']); $i++) { echo ...READ MORE

answered Sep 21, 2018 in Blockchain by slayer
• 29,370 points
704 views
+1 vote
1 answer

I would like to create a blockchain network which will stay at the same level of complexity, is it possible?

You can very easily create a cryptocurrency having a ...READ MORE

answered Apr 4, 2018 in Blockchain by Christine
• 15,790 points
795 views
0 votes
1 answer

Can a hacker change data of a smart sontract without call contract function?

A contract's content cannot be changed internally. ...READ MORE

answered Apr 8, 2018 in Blockchain by Shashank
• 10,400 points
654 views
0 votes
1 answer

How do I add multiple recipients for transactions via Blockchain API?

Convert the recipes into JSON objects. x = ...READ MORE

answered Jul 6, 2018 in Blockchain by Perry
• 17,100 points
803 views
0 votes
1 answer

Python request module for bitcoin json rpc

This should work: #!/usr/bin/env python import getpass import json import requests ...READ MORE

answered Aug 28, 2018 in Blockchain by digger
• 26,740 points
2,315 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,879 views
+1 vote
3 answers

Removing double quotes from a string from JSON response in PHP

Just remove the json_encode call, and it should work: $resp ...READ MORE

answered Sep 12, 2018 in Blockchain by digger
• 26,740 points
45,024 views
0 votes
1 answer

How to transact custom token instead of ethers using JSON rpc?

First create your custom token. Then develop ...READ MORE

answered Jul 10, 2018 in Blockchain by digger
• 26,740 points
1,031 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP