hyperledger-fabrichyperledger-fabric-cahyperledger-fabric-sdk-java

How do I force set the user context without a key value store or wallet?


For testing purposes, I already have the public key + private key + certificate on hand (can just hardcode it), and I can set up the CA through the connection profile, but how would I invoke a transaction without setting up the filesystem key value store/wallet?


Solution

  • Use the InMemoryWallet class - see https://fabric-sdk-node.github.io/master/module-fabric-network.InMemoryWallet.html

    example:

     const credPath = '/home/demo/mynetwork/crypto-material/crypto-config/peerOrganizations/org1.example.com/users/User1@org1.example.com/msp';
     const cert = fs.readFileSync(credPath + '/cert.pem').toString();
     const key = fs.readFileSync(credPath + '/key.pem').toString();
     const inMemoryWallet = new InMemoryWallet();
     await inMemoryWallet.import('admin', X509WalletMixin.createIdentity('Org1MSP', cert, key));
    

    or check out the integration test scripts for Fabric Node SDK