简体   繁体   中英

Printing bitcoin address transactions using blockchain API

I'm building a php site and need some of the functionality provided by the blockchain API ( https://github.com/blockchain/api-v1-client-php )

I'm trying to print out an overview of all transactions done to a specific address, but no success so far.

I've gathered the info of the address, but the transactions are stored in an array (as written in the documentations), and can't get them out.

$limit = 50;
$offset = 0;
$address = "xxx";
$address_info = $Blockchain->Explorer->getAddress($address, $limit, $offset);
echo $address_info->n_tx; //just as a test, this works

$transactions = $address_info->transactions; //no error here
echo $transactions->version;

The last line of code throws this error: "Trying to get property of non-object". echo $transactions[0] also doesn't work.

The github page doesn't feature any examples of printing out transactions.

The var_dump function of $transactions produces this:

array (size=2)
  0 => 
    object(Blockchain\Explorer\Transaction)[11]
      public 'double_spend' => boolean false
      public 'block_height' => int 382334
      public 'time' => int 1446833376
      public 'lock_time' => int 0
      public 'relayed_by' => string '192.99.2.32' (length=11)
      public 'hash' => string 'd9f625afe46ea8bbe9dc74484cefbcb15fbd6887a1bc619b44161114b78ab038' (length=64)
      public 'tx_index' => int 109866616
      public 'version' => int 1
      public 'size' => int 374
      public 'inputs' => 
        array (size=2)
          0 => 
            object(Blockchain\Explorer\Input)[12]
              ...
          1 => 
            object(Blockchain\Explorer\Input)[13]
              ...
      public 'outputs' => 
        array (size=2)
          0 => 
            object(Blockchain\Explorer\Output)[14]
              ...
          1 => 
            object(Blockchain\Explorer\Output)[15]
              ...

Any ideas?

$transactions is a PHP array, not an object. You can access the version of the first object in the array using $transactions[0]->version , or iterate through the array using something like foreach ($transaction in $transactions) { ... } .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM