Get Latest Transactions on the CSCL

Posted by

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s