I want to call one chaincode from another chaincode in fabric 1.0 so I have some questions: 1) can we install two chaincode on single peer 2) if we install two chaincode on different peer, how we can call one into another? 3)if anybody having sample example please share.
This is should be pretty straight forward to achieve, here is an example:
// Invoke
func (am *accountManagement) Invoke(stub shim.ChaincodeStubInterface) peer.Response {
actionName, params := stub.GetFunctionAndParameters()
if actionName == "callAnotherCC" {
chainCodeArgs := util.ToChaincodeArgs("anotherCCFunc", "paramA")
response := stub.InvokeChaincode("anotherCCName", chainCodeArgs, "channelName")
if response.Status != shim.OK {
return shim.Error(response.Message)
}
return shim.Success(nil)
}
// NOTE: This is an example, hence assuming only valid call is to call another chaincode
return shim.Error(fmt.Sprintf("[ERROR] No <%s> action defined", actionName))
}
As @Gari, correctly stated in the comment:
It's very important to make sure that both chaincodes are installed on each endorsing peer
Consider to read also following material:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With