[英]facing error “FileSystemWallet is not a constructor” while executing enrollAdmin.js
Facing error " TypeError: FileSystemWallet is not a constructor " on line const wallet = new FileSystemWallet(walletPath);面临错误“ TypeError:FileSystemWallet 不是构造函数”在线const wallet = new FileSystemWallet(walletPath);
Details are as below "详情如下"
NPM version: 6.14.4 Node Version: v10.21.0 NPM 版本:6.14.4 节点版本:v10.21.0
below is the code trying to execute, Please help on this and Thanks in advance.以下是尝试执行的代码,请对此提供帮助并提前致谢。
'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);
}
}
I ran into this issue recently too and I think it's because the master branch of the fabric-sdk-node package doesn't have that class any longer.我最近也遇到了这个问题,我认为这是因为 fabric-sdk-node package 的主分支不再有那个 class 。 They've moved from FileSystemWallet in v1.4 to FileSystemWalletStore in v2.2 / the current master branch.
他们已经从 v1.4 中的FileSystemWallet移动到 v2.2 中的FileSystemWalletStore / 当前的 master 分支。
Try:尝试:
...
const { Wallets, X509WalletMixin } = require('fabric-network');
...
async function main() {
...
const wallet = await Wallets.newFileSystemWallet(walletPath);
...
}
I'm still trying to work out how to open an existing wallet without overwriting an existing so I'll update this post if/when I figure it out.我仍在尝试解决如何在不覆盖现有钱包的情况下打开现有钱包,所以如果/当我弄清楚时,我会更新这篇文章。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.