Get Address (Account) on the CSCL

Posted by

To retrieve information on an address use the following script

<?php

$daemon = 'http://xxxxxxxx:8443';

function getAccount($account,$daemon) {

$ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, $daemon);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, '

       { "method" : "account_info", 
			"params" : 
			[ 	{
				"account": "'.$account.'",
				"strict": true,
				"ledger_index": "current",
				"queue": true
				}
			] }

    ');
    curl_setopt($ch, CURLOPT_POST, 1);

    $headers = array();
    $headers[] = "Content-Type: application/x-www-form-urlencoded";
    curl_setopt($ch, CURLOPT_HEADER, 0);

    $result = curl_exec($ch);
    if (curl_errno($ch)) {
        echo 'Error:' . curl_error($ch);
    }
    curl_close ($ch);
    if (empty($result)) {
      throw new Exception("Content is empty.");
    }
    $obj = json_decode($result, 1);
    if (empty($obj)) {
      throw new Exception("JSON decode failed, content: " .$result);
    }
            return $obj;
}

$account = getAccount('cnKwvH78cUTAvZbm8TWZXqdsWhmjcok1Xm',$daemon);

var_dump($account);


?>

This will give the response of

array(1) {
  ["result"]=>
  array(5) {
    ["account_data"]=>
    array(9) {
      ["Account"]=>
      string(34) "cnKwvH78cUTAvZbm8TWZXqdsWhmjcok1Xm"
      ["Balance"]=>
      string(17) "38952191430400000"
      ["Flags"]=>
      int(0)
      ["LedgerEntryType"]=>
      string(11) "AccountRoot"
      ["OwnerCount"]=>
      int(0)
      ["PreviousTxnID"]=>
      string(64) "9206D86D80FC2F80922B38F10F43CD2ACE8C80BE0280E2DE6781707CC9FA073A"
      ["PreviousTxnLgrSeq"]=>
      int(191609)
      ["Sequence"]=>
      int(675)
      ["index"]=>
      string(64) "D704E1180AEC7C58F832B9C80AEEF5C8A58BBEBBA56EA70B56327859E97D3C2E"
    }
    ["ledger_current_index"]=>
    int(191628)
    ["queue_data"]=>
    array(1) {
      ["txn_count"]=>
      int(0)
    }
    ["status"]=>
    string(7) "success"
    ["validated"]=>
    bool(false)
  }
}