【问题标题】:Printing bitcoin address transactions using blockchain API使用区块链 API 打印比特币地址交易
【发布时间】:2016-02-08 14:41:37
【问题描述】:

我正在构建一个 php 站点,需要区块链 API (https://github.com/blockchain/api-v1-client-php) 提供的一些功能

我正在尝试打印对特定地址进行的所有交易的概览,但到目前为止没有成功。

我已经收集了地址的信息,但是交易存储在一个数组中(如文档中所述),无法将它们取出。

$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;

最后一行代码抛出此错误:“尝试获取非对象的属性”。 echo $transactions[0] 也不起作用。

github 页面没有任何打印交易的示例。

$transactions 的 var_dump 函数产生这个:

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]
              ...

有什么想法吗?

【问题讨论】:

  • 尝试var_dump( $transactions ) 或print_r( $transactions ) 看看它包含什么
  • 谢谢!,我之前尝试过,这会打印整个数组,但我想在单独的变量中处理数组内容。 var_dump 结果如下: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) ...

标签: php arrays api bitcoin blockchain


【解决方案1】:

$transactions 是一个 PHP 数组,而不是一个对象。您可以使用$transactions[0]->version 访问数组中第一个对象的版本,或使用foreach ($transaction in $transactions) { ... } 之类的方式遍历数组。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-01-09
    • 1970-01-01
    • 1970-01-01
    • 2021-01-15
    • 1970-01-01
    • 2018-01-12
    • 1970-01-01
    • 2015-03-28
    相关资源
    最近更新 更多