Bablu Vishwakarma
Bablu Vishwakarma

Reputation: 11

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);

Details are as below "

NPM version : 6.14.4 Node Version: 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);
        }
}

Upvotes: 1

Views: 1674

Answers (1)

Taur1ne
Taur1ne

Reputation: 61

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. They've moved from FileSystemWallet in v1.4 to FileSystemWalletStore in v2.2 / the current master branch.

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.

Upvotes: 6

Related Questions