Home > front end >  How to access final balance from blockchain
How to access final balance from blockchain

Time:10-01

I have the following url:

https://blockchain.info/multiaddr?active=1AT4ES3ee1N6iBzzbdK8xvcAV3CBTRKcbS|1FHcYth4LRJMwNx2y8NR5DH7sYCiVzXs3Y&n=1

I want to access the final_balance from the output of the url.

I have the following code:

 $value = file_get_contents($url);
    $FinalBalance = $value["final_balance"];
    var_dump($FinalBalance);

Error PHP Warning:  Illegal string offset 'final_balance'

I also tried the following code:

 $value = file_get_contents($url);
    $json = json_decode($value);
    var_dump($json);
        $FinalBalance = $json["final_balance"];
    var_dump($Final_Balance);
Error PHP Fatal error:  Uncaught Error: Cannot use object of type stdClass as array

CodePudding user response:

Your are near to finish that stuff but I will write down desired solution. Please have a look.

 $url="https://blockchain.info/multiaddr?active=1AT4ES3ee1N6iBzzbdK8xvcAV3CBTRKcbS|1FHcYth4LRJMwNx2y8NR5DH7sYCiVzXs3Y&n=1";
 $value = file_get_contents($url);
 $FinalBalance = $value;
 $data=json_decode($FinalBalance);
 echo $data->wallet->final_balance;
 echo $data->addresses[0]->final_balance;
 echo $data->addresses[1]->final_balance;
 exit;

You are going to access the inner object so you have to provide proper reference whether it is an array or an object.

  • Related