首页 > 解决方案 > 为 IBM Block chain Hyperledger Fabric 运行enrollAdmin.js 时遇到错误

问题描述

我正在遵循 GitHub 上的教程,使用 IBM Blockchain(hyperledger 结构,我按照此处的步骤进行云部署:https ://github.com/IBM/evote 唯一的变化是我使用了 Hyperledger 结构 v2。 2、node.js v 15.4.0 在第 6 步“运行应用程序”中,当我尝试运行 nodeenrollAdmin.js 命令时收到错误消息。我在终端中收到的错误消息如下:

2021-04-22T08:57:53.453Z - error: [FabricCAClientService.js]: Failed to enroll app-admin, error:%o message=Calling enroll endpoint failed, CONNECTION Timeout, stack=Error: Calling enroll endpoint failed, CONNECTION Timeout
    at TLSSocket.<anonymous> (/home/h-ghazali/node_modules/fabric-ca-client/lib/FabricCAClient.js:315:13)
    at TLSSocket.emit (node:events:381:22)
    at TLSSocket.Socket._onTimeout (node:net:481:8)
    at listOnTimeout (node:internal/timers:557:17)
    at processTimers (node:internal/timers:500:7)
Failed to enroll admin user ' + app-admin + : Error: Calling enroll endpoint failed, CONNECTION Timeout


enrollAdmin.js 文件如下

/*
 * SPDX-License-Identifier: Apache-2.0
 */

'use strict';

const FabricCAServices = require('fabric-ca-client');
const { FileSystemWallet, X509WalletMixin } = require('fabric-network');
const fs = require('fs');
const path = require('path');

// capture network variables from config.json
const configPath = path.join(process.cwd(), './config.json');
const configJSON = fs.readFileSync(configPath, 'utf8');
const config = JSON.parse(configJSON);

// let connection_file = config.connection_file;
let appAdmin = config.appAdmin;
let appAdminSecret = config.appAdminSecret;
let orgMSPID = config.orgMSPID;
let caName = config.caName;

// const ccpPath = path.join(process.cwd(), './www/blockchain/ibpConnection.json');
// const ccpPath = path.join(process.cwd(), './ibpConnection.json');
// const ccpJSON = fs.readFileSync(ccpPath, 'utf8');
// const ccp = JSON.parse(ccpJSON);

async function main() {
  try {

    // Create a new CA client for interacting with the CA.
    const caURL = caName;
    const ca = new FabricCAServices(caURL);

    // Create a new file system based wallet for managing identities.
    const walletPath = path.join(process.cwd(), 'wallet');
    const wallet = new FileSystemWallet(walletPath);
    console.log(`Wallet path: ${walletPath}`);

    // Check to see if we've already enrolled the admin user.
    const adminExists = await wallet.exists(appAdmin);
    if (adminExists) {
      console.log('An identity for the admin user "admin" already exists in the wallet');
      return;
    }

    // Enroll the admin user, and import the new identity into the wallet.
    const enrollment = await ca.enroll({ enrollmentID: appAdmin, enrollmentSecret: appAdminSecret });
    const identity = X509WalletMixin.createIdentity(orgMSPID, enrollment.certificate, enrollment.key.toBytes());
    wallet.import(appAdmin, identity);
    console.log('msg: Successfully enrolled admin user ' + appAdmin + ' and imported it into the wallet');

  } catch (error) {
    console.error(`Failed to enroll admin user ' + ${appAdmin} + : ${error}`);
    process.exit(1);
  }
}

main();

标签: node.jsibm-cloudhyperledger-fabricblockchain

解决方案


推荐阅读