Re: API to get local MSPID in chaincode? #fabric #fabric-questions #fabric-chaincode


Tsvetan Georgiev
 

Hi,
If I get your questions right, you want to fetch the MSPID of the peer that starts/endorses the chaincode. For that purpose you can use the chaincode shim API. In case it is java based chaincode you can look at the method String getMspId(); of the shim: https://github.com/hyperledger/fabric-chaincode-java/blob/master/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/shim/ChaincodeStub.java
You have similar method in NodeJS shim: https://hyperledger.github.io/fabric-chaincode-node/release-2.1/api/fabric-shim.ChaincodeStub.html#getMspID__anchor

If you want to fetch the MSPID (as you mention above) of the user who requests for endorsement you can do that through the caller identity (CID) - see method getCreator() of the ChaincodeStub.

Join fabric@lists.hyperledger.org to automatically receive all group messages.