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
• 26,740 points

2 answers to this question.

+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,360 points

selected May 3, 2019 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, 2019 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
• 17,100 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, 2019 in Blockchain by Omkar
• 69,230 points
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
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,360 points
0 votes
1 answer
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP