执行enrollAdmin.js时遇到错误“ FileSystemWallet不是构造函数”

时间:2020-06-24 13:24:27

标签: node.js

面对错误“ TypeError:FileSystemWallet不是构造函数” 在线 const wallet = new FileSystemWallet(walletPath);

详细信息如下“

NPM版本:6.14.4 节点版本:v10.21.0

以下是尝试执行的代码,请对此提供帮助,并提前致谢。

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

const ccpPath = path.resolve(__dirname, 'connection-banka.json');
const ccpJSON = fs.readFileSync(ccpPath, 'utf8');
const ccp = JSON.parse(ccpJSON);

main();

async function main() {
try {
    const caInfo = ccp.certificateAuthorities['ca.banka.example.com'];
    const caTLSCACerts = caInfo.tlsCACerts.pem;
    const ca = new FabricCAServices(caInfo.url, { trustedRoots:caTLSCACerts, verify: false }, caInfo.caName);
    const walletPath = path.join(process.cwd(), 'wallet-BankA');
    console.log(`Wallet path: ${walletPath}`);
    const wallet = new FileSystemWallet(walletPath);
    console.log(`Wallet : ${wallet}`);

    const adminExists = await wallet.exists('admin');
    if (adminExists) {
        console.log('An identity for the admin user "admin" already exists in the wallet');
        return;
    }

    const enrollment = await ca.enroll({ enrollmentID: 'admin',enrollmentSecret: 'adminpw' });
    const identity = X509WalletMixin.createIdentity('bankaMSP',enrollment.certificate, enrollment.key.toBytes());
    await wallet.import('admin', identity);
    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);
        }
}

1 个答案:

答案 0 :(得分:2)

我最近也遇到了这个问题,我认为这是因为fabric-sdk-node软件包的master分支不再具有该类了。它们已从v1.4中的FileSystemWallet移至v2.2 /当前的master分支中的FileSystemWalletStore

尝试:

...
const { Wallets, X509WalletMixin } = require('fabric-network');
...
async function main() {
   ...
   const wallet = await Wallets.newFileSystemWallet(walletPath);
   ...
}

我仍在尝试如何在不覆盖现有钱包的情况下打开现有钱包,因此如果/在我弄清楚时会更新此帖子。