Get Ledger and relating transactions on the CSCL

If you are looking to get the that relates to a Ledger (Block) on the CSCL use the following script

<?php

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

function getLedger($index, $daemon) {

$ch = curl_init();

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

       { "method" : "ledger", 
			"params" : 
			[ 	{"ledger_index": '.$index.',"transactions": 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;
}

$ledgerArray = getLedger(172234, $daemon);

var_dump($ledgerArray);


?>

This will give the output of

array(1) {
  ["result"]=>
  array(5) {
    ["ledger"]=>
    array(17) {
      ["accepted"]=>
      bool(true)
      ["account_hash"]=>
      string(64) "3609A9D1AC6D6137F8CE7A65E67D4032D0AF6204A85B2ACDB164F37C7CBD6529"
      ["close_flags"]=>
      int(0)
      ["close_time"]=>
      int(633110120)
      ["close_time_human"]=>
      string(20) "2020-Jan-23 15:55:20"
      ["close_time_resolution"]=>
      int(10)
      ["closed"]=>
      bool(true)
      ["hash"]=>
      string(64) "F1F1132376CA09E1FDE281C5B03234F2517C9A7C2E360F292B77F8337F9E4ADA"
      ["ledger_hash"]=>
      string(64) "F1F1132376CA09E1FDE281C5B03234F2517C9A7C2E360F292B77F8337F9E4ADA"
      ["ledger_index"]=>
      string(6) "172234"
      ["parent_close_time"]=>
      int(633110112)
      ["parent_hash"]=>
      string(64) "207C1D118F0F6AAE909302798A7FB7F00FBE1BF372D59F9841FA33524A0DDEDA"
      ["seqNum"]=>
      string(6) "172234"
      ["totalCoins"]=>
      string(19) "3999999992024999979"
      ["total_coins"]=>
      string(19) "3999999992024999979"
      ["transaction_hash"]=>
      string(64) "E5818E0D2DC182E67F894E7D283BCE314024BCD8A8863207ECC9566DC1B8D7D9"
      ["transactions"]=>
      array(1) {
        [0]=>
        string(64) "0E79AD34FB547E9D356A71CD08B6CD960DCAA8CB8B07ED25388D003D86AAB68C"
      }
    }
    ["ledger_hash"]=>
    string(64) "F1F1132376CA09E1FDE281C5B03234F2517C9A7C2E360F292B77F8337F9E4ADA"
    ["ledger_index"]=>
    int(172234)
    ["status"]=>
    string(7) "success"
    ["validated"]=>
    bool(true)
  }
}

Get List of Tokens on CSCL

To retrieve an array of tokens available on the CSCL use the following script

<?php

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

function tokens($daemon) {

$ch = curl_init();

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

       { "method" : "config_info", 
			"params" : 
			[ 	{
				
				}
			] }

    ');
    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;
}

$get = tokens($daemon);

var_dump($get);


?>

This will give a response of


array(1) {
  ["result"]=>
  array(4) {
    ["configuration"]=>
    array(5) {
      [0]=>
      array(3) {
        ["ConfigData"]=>
        array(1) {
          [0]=>
          array(1) {
            ["account"]=>
            string(34) "chXKNwZUjRLxdUumHoWji6iAAs2YLPV5eY"
          }
        }
        ["ConfigID"]=>
        int(4)
        ["ConfigType"]=>
        string(16) "Blacklist_Signer"
      }
      [1]=>
      array(3) {
        ["ConfigData"]=>
        array(15) {
          [0]=>
          array(10) {
            ["apiEndpoint"]=>
            string(28) "https://api.100.com/endpoint"
            ["contactEmail"]=>
            string(12) "info@100.com"
            ["extraFeeFactor"]=>
            int(0)
            ["flags"]=>
            int(0)
            ["fullName"]=>
            string(7) "100.com"
            ["iconURL"]=>
            string(94) "https://raw.githubusercontent.com/casinocoin/CasinoCoin-Assets/master/v4/100-coin-icon-512.png"
            ["issuer"]=>
            string(34) "cEWTA66ypmFVzZksJntBetbeQdDqnRLA44"
            ["token"]=>
            string(3) "100"
            ["totalSupply"]=>
            string(12) "250000000000"
            ["website"]=>
            string(19) "https://www.100.com"
          }
          [1]=>
          array(10) {
            ["apiEndpoint"]=>
            string(25) "https://api.pokercoin.com"
            ["contactEmail"]=>
            string(18) "info@pokercoin.com"
            ["extraFeeFactor"]=>
            int(0)
            ["flags"]=>
            int(0)
            ["fullName"]=>
            string(9) "PokerCoin"
            ["iconURL"]=>
            string(96) "https://raw.githubusercontent.com/casinocoin/CasinoCoin-Assets/master/v4/poker-coin-icon-512.png"
            ["issuer"]=>
            string(34) "cfiikpLkuWH2rYK1b7fV7RziYVuqUY6koo"
            ["token"]=>
            string(3) "PCN"
            ["totalSupply"]=>
            string(10) "1000000000"
            ["website"]=>
            string(25) "https://www.pokercoin.com"
          }
        .............

Get Address (Account) on the CSCL

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)
  }
}

Get Transaction on the CSCL

To retrieve data on a transaction use the script below

<?php

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

function getTx($tx,$daemon) {

$ch = curl_init();

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

       { "method" : "tx", "params" : [ {"transaction": "'.$tx.'"}] }

    ');
    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;
}

$tx = getTx('9206D86D80FC2F80922B38F10F43CD2ACE8C80BE0280E2DE6781707CC9FA073A',$daemon);

var_dump($tx);


?>

This gives the following output

array(1) {
  ["result"]=>
  array(17) {
    ["Account"]=>
    string(34) "cnKwvH78cUTAvZbm8TWZXqdsWhmjcok1Xm"
    ["Amount"]=>
    string(13) "1000000000000"
    ["Destination"]=>
    string(34) "cKyC8KSX1WZH6jTkJb4ntouYvQkuJ1RZVC"
    ["Fee"]=>
    string(8) "25000000"
    ["Flags"]=>
    int(2147483648)
    ["LastLedgerSequence"]=>
    int(191613)
    ["Sequence"]=>
    int(674)
    ["SigningPubKey"]=>
    string(66) "02F845799CAE9AE8421E0AEE0D93526AD21D882A911D93A46AFB17826B923A41C0"
    ["TransactionType"]=>
    string(7) "Payment"
    ["TxnSignature"]=>
    string(140) "3044022039A974644241ED22A4F733CF61B2CD40CED342B926F83704CC6F70CFA3D182B8022047150EA7F903B4CCB1BC085C1D9145DDE13687FDF008EB5DEB344FC79C4495A3"
    ["date"]=>
    int(633433350)
    ["hash"]=>
    string(64) "9206D86D80FC2F80922B38F10F43CD2ACE8C80BE0280E2DE6781707CC9FA073A"
    ["inLedger"]=>
    int(191609)
    ["ledger_index"]=>
    int(191609)
    ["meta"]=>
    array(4) {
      ["AffectedNodes"]=>
      array(2) {
        [0]=>
        array(1) {
          ["ModifiedNode"]=>
          array(6) {
            ["FinalFields"]=>
            array(5) {
              ["Account"]=>
              string(34) "cKyC8KSX1WZH6jTkJb4ntouYvQkuJ1RZVC"
              ["Balance"]=>
              string(13) "2000000000000"
              ["Flags"]=>
              int(0)
              ["OwnerCount"]=>
              int(0)
              ["Sequence"]=>
              int(1)
            }
            ["LedgerEntryType"]=>
            string(11) "AccountRoot"
            ["LedgerIndex"]=>
            string(64) "8DEA01AE8B1765DD9BBC9B0AC3986A1CEB59F3F0843C20052A0060ACE20D1532"
            ["PreviousFields"]=>
            array(1) {
              ["Balance"]=>
              string(13) "1000000000000"
            }
            ["PreviousTxnID"]=>
            string(64) "B04F53E22DBB4723D8C35622A2985FC27A301F9BDFD2F4C9C3D1184E63A156D2"
            ["PreviousTxnLgrSeq"]=>
            int(191606)
          }
        }
        [1]=>
        array(1) {
          ["ModifiedNode"]=>
          array(6) {
            ["FinalFields"]=>
            array(5) {
              ["Account"]=>
              string(34) "cnKwvH78cUTAvZbm8TWZXqdsWhmjcok1Xm"
              ["Balance"]=>
              string(17) "38952191430400000"
              ["Flags"]=>
              int(0)
              ["OwnerCount"]=>
              int(0)
              ["Sequence"]=>
              int(675)
            }
            ["LedgerEntryType"]=>
            string(11) "AccountRoot"
            ["LedgerIndex"]=>
            string(64) "D704E1180AEC7C58F832B9C80AEEF5C8A58BBEBBA56EA70B56327859E97D3C2E"
            ["PreviousFields"]=>
            array(2) {
              ["Balance"]=>
              string(17) "38953191455400000"
              ["Sequence"]=>
              int(674)
            }
            ["PreviousTxnID"]=>
            string(64) "B04F53E22DBB4723D8C35622A2985FC27A301F9BDFD2F4C9C3D1184E63A156D2"
            ["PreviousTxnLgrSeq"]=>
            int(191606)
          }
        }
      }
      ["TransactionIndex"]=>
      int(0)
      ["TransactionResult"]=>
      string(10) "tesSUCCESS"
      ["delivered_amount"]=>
      string(13) "1000000000000"
    }
    ["status"]=>
    string(7) "success"
    ["validated"]=>
    bool(true)
  }
}

Get Latest Transactions on the CSCL

To receive a list of the latest Transactions use the following script

<?php

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

function latestTx($daemon) {

$ch = curl_init();

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

       { "method" : "tx_history", "params" : [ {"start": 0}] }

    ');
    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;
}

$array = latestTx($daemon);

var_dump($array);


?>

This will give an output of

array(1) {
  ["result"]=>
  array(3) {
    ["index"]=>
    int(0)
    ["status"]=>
    string(7) "success"
    ["txs"]=>
    array(20) {
      [0]=>
      array(13) {
        ["Account"]=>
        string(34) "cnKwvH78cUTAvZbm8TWZXqdsWhmjcok1Xm"
        ["Amount"]=>
        string(13) "1000000000000"
        ["Destination"]=>
        string(34) "cKyC8KSX1WZH6jTkJb4ntouYvQkuJ1RZVC"
        ["Fee"]=>
        string(8) "25000000"
        ["Flags"]=>
        int(2147483648)
        ["LastLedgerSequence"]=>
        int(191613)
        ["Sequence"]=>
        int(674)
        ["SigningPubKey"]=>
        string(66) "02F845799CAE9AE8421E0AEE0D93526AD21D882A911D93A46AFB17826B923A41C0"
        ["TransactionType"]=>
        string(7) "Payment"
        ["TxnSignature"]=>
        string(140) "3044022039A974644241ED22A4F733CF61B2CD40CED342B926F83704CC6F70CFA3D182B8022047150EA7F903B4CCB1BC085C1D9145DDE13687FDF008EB5DEB344FC79C4495A3"
        ["hash"]=>
        string(64) "9206D86D80FC2F80922B38F10F43CD2ACE8C80BE0280E2DE6781707CC9FA073A"
        ["inLedger"]=>
        int(191609)
        ["ledger_index"]=>
        int(191609)
      }
      [1]=>
      array(13) {
        ["Account"]=>
        string(34) "cnKwvH78cUTAvZbm8TWZXqdsWhmjcok1Xm"
        ["Amount"]=>
        string(13) "1000000000000"
        ["Destination"]=>
        string(34) "cKyC8KSX1WZH6jTkJb4ntouYvQkuJ1RZVC"
        ["Fee"]=>
        string(8) "25000000"
        ["Flags"]=>
        int(2147483648)
        ["LastLedgerSequence"]=>
        int(191610)
        ["Sequence"]=>
        int(673)
        ["SigningPubKey"]=>
        string(66) "02F845799CAE9AE8421E0AEE0D93526AD21D882A911D93A46AFB17826B923A41C0"
        ["TransactionType"]=>
        string(7) "Payment"
        ["TxnSignature"]=>
        string(140) "30440220659DA5093FAC1239711CDA979111BBB292BD09416278181F5267A51A6810C235022011E48EBE4E8BC534DBBC55EEF50BCDE9AE987F6DD9BFB29A008B6C9448F492C8"
        ["hash"]=>
        string(64) "B04F53E22DBB4723D8C35622A2985FC27A301F9BDFD2F4C9C3D1184E63A156D2"
        ["inLedger"]=>
        int(191606)
        ["ledger_index"]=>
        int(191606)
      }
........

Connecting to a CSCL server

I am using PHP to connect via CURL to the ledger and to test my connection am using the following script

<?php

$daemon = 'http://xxxxxxx:8443'; // default port 5005

function server($daemon) {
/////////// check server info
$ch = curl_init();

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

       { "method" : "server_info", "params" : [ {}] }

    ');
    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;
}

$server = server($daemon);

var_dump($server);


?>

A successful connection will bring a result such as below

array(1) {
  ["result"]=>
  array(2) {
    ["info"]=>
    array(18) {
      ["build_version"]=>
      string(7) "4.0.5-4"
      ["complete_ledgers"]=>
      string(8) "1-191613"
      ["crn_activated"]=>
      bool(true)
      ["crn_domain_name"]=>
      string(10) "xxx.xxxxxxx.xxx"
      ["crn_public_key"]=>
      string(52) "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
      ["hostid"]=>
      string(3) "csc"
      ["io_latency_ms"]=>
      int(1)
      ["last_close"]=>
      array(2) {
        ["converge_time_s"]=>
        float(1.998)
        ["proposers"]=>
        int(8)
      }
      ["load"]=>
      array(2) {
        ["job_types"]=>
        array(2) {
          [0]=>
          array(2) {
            ["in_progress"]=>
            int(1)
            ["job_type"]=>
            string(13) "clientCommand"
          }
          [1]=>
          array(2) {
            ["job_type"]=>
            string(11) "peerCommand"
            ["per_second"]=>
            int(15)
          }
        }
        ["threads"]=>
        int(4)
      }
      ["load_factor"]=>
      int(1)
      ["peers"]=>
      int(36)
      ["pubkey_node"]=>
      string(52) "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
      ["pubkey_validator"]=>
      string(4) "none"
      ["server_state"]=>
      string(4) "full"
      ["state_accounting"]=>
      array(5) {
        ["connected"]=>
        array(2) {
          ["duration_us"]=>
          string(8) "38004520"
          ["transitions"]=>
          int(1)
        }
        ["disconnected"]=>
        array(2) {
          ["duration_us"]=>
          string(7) "1136881"
          ["transitions"]=>
          int(1)
        }
        ["full"]=>
        array(2) {
          ["duration_us"]=>
          string(12) "222333000321"
          ["transitions"]=>
          int(1)
        }
        ["syncing"]=>
        array(2) {
          ["duration_us"]=>
          string(9) "111007130"
          ["transitions"]=>
          int(1)
        }
        ["tracking"]=>
        array(2) {
          ["duration_us"]=>
          string(2) "83"
          ["transitions"]=>
          int(1)
        }
      }
      ["uptime"]=>
      int(222483)
      ["validated_ledger"]=>
      array(6) {
        ["age"]=>
        int(127)
        ["base_fee_csc"]=>
        float(0.25)
        ["hash"]=>
        string(64) "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
        ["reserve_base_csc"]=>
        int(10)
        ["reserve_inc_csc"]=>
        int(1)
        ["seq"]=>
        int(191613)
      }
      ["validation_quorum"]=>
      int(6)
    }
    ["status"]=>
    string(7) "success"
  }
}