Explore Courses Blog Tutorials Interview Questions
0 votes
in Blockchain by (4.1k points)

I wrote a chaincode1(deployed on one peer of ORG1) which accepts the details from the user and store it into the ledger. Now I want to write a chaincode2(deployed on a peer of ORG2) which takes some data from the chaincode1 for computation. This chaincode2 should be called by chaincode1 with specific details required for computation. How can i achieve this thing and where should I test it?

1 Answer

0 votes
by (14.4k points)

There are few preconditions for starters:

  1. If you'd like to have chaincode1 to invoke chaincode2, you need both the chaincodes to be installed the same peer 
  2. You need to make sure this peer part of both channels

Next, you need to leverage the following API:

// 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


chainCodeArgs := util.ToChaincodeArgs("arg1", "arg2")

response := stub.InvokeChaincode("chaincodeName", chainCodeArgs, "channelID")

if response.Status != shim.OK {

    return shim.Error(response.Message)


Browse Categories