How to assign identity to fabric-client instance?

情到浓时终转凉″ 提交于 2020-01-06 07:56:13

问题


I am unable to install node chaincode using fabric-node-sdk.
I am getting the following error:

installChaincode error No identity has been assigned to this client

I am using following script

const Client = require("fabric-client");
const path = require("path");
const os = require("os");
const client = new Client();
const deploy = async () => {
  const connectionOpts = {
    name: "peer1",
    "request-timeout": 7000,
    pem: path.resolve(
      os.homedir,
      "/fabric-samples/chaincode-docker-devmode/msp/signcerts/peer.pem"
    ),
    "ssl-target-name-override": "peer"
  };
  const peer = client.newPeer("grpc://172.18.0.3:7052", connectionOpts);
  const request = {
    targets: peer,
    chaincodePath: path.resolve(
      os.homedir + "/fabric-samples/chaincode/chaincode_example02/node"
    ),
    chaincodeId: "myc",
    chaincodeVersion: "v0",
    chaincodeType: "node"
  };

  const result = await client.installChaincode(request, 6000);
  console.log(await result);
};

deploy();

How do I assign identity to client?
In the documentation, it is not demonstrated what arguments it required and how to assign identity.


回答1:


Peer node want to know who is making the transaction. Try using this method before the install chincode transaction:

client.setAdminSigningIdentity(private_key, certificate, mspid)

Where:
private_key: the private key PEM string
certificate: the PEM-encoded string of certificate
mspid: The Member Service Provider id for the local signing identity (i.e 'Org1MSP')

In the chaincode install request, you need the txId:

client.setAdminSigningIdentity(private_key, certificate, mspid)
const request = {
  targets: peer,
  chaincodePath: path.resolve(
    os.homedir + "/fabric-samples/chaincode/chaincode_example02/node"
  ),
  chaincodeId: "myc",
  chaincodeVersion: "v0",
  chaincodeType: "node",
  txId: client.newTransactionID(true)
};

const result = await client.installChaincode(request, 6000);
console.log(await result);



回答2:


I faced the same issue as well and it is resolved after adding the below line, i.e., channel initialization.

await channel.initialize({ discover: true });

source: https://fabric-sdk-node.github.io/master/tutorial-discovery.html



来源:https://stackoverflow.com/questions/54536308/how-to-assign-identity-to-fabric-client-instance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!