Search code examples
hyperledger-fabrichyperledgerhyperledger-fabric-cahyperledger-chaincodehyperledger-fabric-sdk-js

Hyperledger Fabric invoking chaincode from Node.js using user artifacts generated by configtxgen. How?


If I understand things correctly, Node.js client examples enroll users, create wallets and then utilize these newly generated identities to perform transactions. At the same time examples for fabric-tools/CLI utilize identities/users generated with configtxgen, there is no enrollment or wallet creation ongoing. I can make both of these examples running for my purposes.

What I miss is an example of using the configtxgen generated admins/users from Node.js client, creating wallet for them etc? Does such example exist? Thank you for your help.


Solution

  • You can simply read from file, save into the wallet and continue the same way as before.

    Declare or replace variables suitably:

            let identity0;
            let wallet0 = new FileSystemWallet(wallet0Path);
            let exists0 = await wallet0.exists(wallet0ID);
            if (!exists0) {
                let user0CertPemRead = fs.readFileSync(user0CertPath).toString('utf8');
                let user0PrvKeyPemRead = fs.readFileSync(user0KeyPath).toString('utf8');
                identity0 = X509WalletMixin.createIdentity(mspID0, user0CertPemRead, user0PrvKeyPemRead);
                await wallet0.import(wallet0ID, identity0);
            } else {
                identity0 = await wallet0.export(wallet0ID);
            }