简体   繁体   中英

Failed to enroll admin user "admin" from Hyperledger Fabric 2.2

I'm trying to run the enrolladmin.js, but I'm receiving this error:

Failed to enroll admin user "admin": TypeError: Cannot read property 'newFileSystemWallet' of undefined

The error shows Wallets as undefined at line:

const wallet = await Wallets.newFileSystemWallet(walletPath);

From the enrolladmin.js:

"use strict";
const FabricCAServices = require("fabric-ca-client");
const { Wallets } = require("fabric-network");
const fs = require("fs");
const path = require("path");

async function main() {
  try {
    // load the network configuration
    const ccpPath = path.resolve(
      __dirname,
      "..",
      "..",
      "..",
      "..",
      "home",
      "my_user",
      "goProject",
      "fabric-samples",
      "udemy_course",
      "Fabric2.2",
      "fabric-samples",
      "test-network",
      "organizations",
      "peerOrganizations",
      "org1.example.com",
      "connection-org1.json"
    );
    const ccp = JSON.parse(fs.readFileSync(ccpPath, "utf8"));

    // Create a new CA client for interacting with the CA.
    const caInfo = ccp.certificateAuthorities["ca.org1.example.com"];
    const caTLSCACerts = caInfo.tlsCACerts.pem;
    const ca = new FabricCAServices(
      caInfo.url,
      { trustedRoots: caTLSCACerts, verify: false },
      caInfo.caName
    );
    // Create a new file system based wallet for managing identities.
    const walletPath = path.join(process.cwd(), "wallet");
    const wallet = await Wallets.newFileSystemWallet(walletPath);

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

    console.log("---05");
    // Enroll the admin user, and import the new identity into the wallet.
    const enrollment = await ca.enroll({
      enrollmentID: "admin",
      enrollmentSecret: "adminpw",
    });
    console.log("---06");
    const x509Identity = {
      credentials: {
        certificate: enrollment.certificate,
        privateKey: enrollment.key.toBytes(),
      },
      mspId: "Org1MSP",
      type: "X.509",
    };
    console.log("---07");
    await wallet.put("admin", x509Identity);
    console.log(
      'Successfully enrolled admin user "admin" and imported it into the wallet'
    );
  } catch (error) {
    console.error(`Failed to enroll admin user "admin": ${error}`);
    process.exit(1);
  }
}

main();

These are the current versions from what I'm using:

  • fabric_version: 2.2.0
  • fabric-ca_version 1.4.7
  • node: v12.15.0
  • npm: 6.13.4

Does anyone know if I'm missing or should change anything?

I tried and it is working. Just check the version of fabric.network library you are using. newFileSystemWallet is in the latest version. Here is the versions I am using -

"fabric-ca-client": "^2.2.11", "fabric-client": "^1.4.19", "fabric.network": "^2.2.11"

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