Can two chaincode interact with each other?

+2 votes
I have two applications that use two different chaincodes. Now for one function to work, I need one chaincode to interact with another chaincode.. I have done this in Ethereum but now I am using Hyperledger and want to implement this.. Is this possible? If yes, then how?
Jul 12, 2018 in Blockchain by digger
• 27,620 points

2 answers to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
+2 votes
Best answer

Yes, it is possible for two chaincodes to interact with each other.. You can use the following API of ChaincodeStubInterface to do it:


// InvokeChaincode locally calls the specified chaincode `Invoke` using the
// same transaction context; that is, chaincode calling chaincode doesn't
// create a new transaction message.
// If the called chaincode is on the same channel, it simply adds the called
// chaincode read set and write set to the calling transaction.
// If the called chaincode is on a different channel,
// only the Response is returned to the calling chaincode; any PutState calls
// from the called chaincode will not have any effect on the ledger; that is,
// the called chaincode on a different channel will not have its read set
// and write set applied to the transaction. Only the calling chaincode's
// read set and write set will be applied to the transaction. Effectively
// the called chaincode on a different channel is a `Query`, which does not
// participate in state validation checks in subsequent commit phase.
// If `channel` is empty, the caller's channel is assumed.
InvokeChaincode(chaincodeName string, args [][]byte, channel string) pb.Response

You can use it like this:

response := stub.InvokeChaincode(chaincodeName, chainCodeArgs, channelName)
answered Jul 12, 2018 by slayer
• 29,040 points

selected May 3 by Omkar
+1 vote

Yes, two chaincodes can interact with each other. To do this, one chaincode has to invoke the other chaincode. Here's a sample code that shows how to do it:

func (stub *TestAPIStub) InvokeChaincode(chaincode1 string, args [][]byte, channel string) pb.Response {
   return pb.Response{}
answered May 3 by Raj

Related Questions In Blockchain

+1 vote
1 answer

How can nodes interact with a Smart Contract?

If you are using Remix IDE to ...READ MORE

answered Apr 27, 2018 in Blockchain by Perry
• 16,450 points
0 votes
1 answer

How can i integrate Omnet++ with ethereum ?? or is there any other simulator which can do this??

You can use Hive Validator. Using this, you ...READ MORE

answered Apr 9 in Blockchain by Omkar
• 65,850 points
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

How do nodes communicate with each other in hyperledger?

First let me tell you that there ...READ MORE

answered Jul 17, 2018 in Blockchain by slayer
• 29,040 points
0 votes
1 answer

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.