Search code examples
hyperledger-fabrichyperledger-chaincode

How to get Transaction Submitter in Hyperledger Fabric chaincode


Currently I'm working with Hyperledger Fabric chaincode and trying to get at least any info regarding current user who invokes/queries chaincode. How do I solve this problem?


Solution

  • I think the lib cid is what you are searching for. The functions GetID and GetMSPID are super helpful to distinguish between the callers.

    Here is an example on how to use it in go

    msp, err := cid.GetMSPID(stub)
    if err != nil {
        return false
    }
    

    This returns the name of the MSP and you can act depending on the result you get. You can even use this to give access to certain functions by MSPID.