简体   繁体   中英

Viewing blockchain blocks using Hyperledger Composer

使用Hyperledger Composer时如何获取和查看添加到区块链的区块?

This can be done using composer-client . Although there are no convenience methods available for this purpose, it is possible to call down to the underlying Hyperledger Fabric SDK API.

Here's some example code for fetching a block by number and pretty-printing it to the console:

const { inspect } = require('util');
const { BusinessNetworkConnection } = require('composer-client');

async function run() {
  const connection = new BusinessNetworkConnection();

  // Connect to the blockchain using admin credentials.
  // These credentials should be available in your local keystore.
  await connection.connect('admin@network');

  // Native API provided through the Fabric SDK, allows much more low-level operations than Composer.
  const nativeApi = connection.getNativeAPI();

  // Connect to the channel where the transactions are happening, the default is "composerchannel".
  const channel = nativeApi.getChannel('composerchannel');

  // Grab a block by it's number
  const block = await channel.queryBlock(4);

  // Enter the matrix
  console.log(inspect(block, { depth: null, colors: true, compact: false }));

  await connection.disconnect();
}

run();

More information about what functionality is exposed through this API can be found in the fabric-sdk-node documentation .

Hyperledger Explorer does this, but it's not a part of Hyperledger Composer. It's a native Fabric tool.

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