How to return value from a chaincode in Hyperledger Fabric?

+1 vote

I would like to get some data from a chaincode transaction to use it for something. I cannot query the chaincode directly because it's too complex. I want to know how to get the data from the chaincode. Please help.

Jun 13, 2018 in Blockchain by nsv999
• 5,030 points
600 views

2 answers to this question.

Your answer

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

Hyperledger Fabric supports only 2 types of transactions on a broader level.

  1. Invoke - If you send the proposal response to the orderer then your values (if any) are written to the state otherwise, any queried value are returned as a part of the proposal response payload.
  2. Deploy - In case of Chaincode deployment transactions where the payload is just a chaincode binary.

If you have a read-only transaction then you could just submit the transaction and get the proposal response payload from the peer(s). The proposal response itself is the result of your query invocation.

Just to be sure to submit the transaction, you can subscribe to the transaction event using the given transaction ID

You can use the same transaction ID to query a peer for the transaction block.

Once you get the transaction payload in JSON you can dig into the JSON and find the return value in proposal response part of the JSON payload.

answered Jun 13, 2018 by Perry
• 16,450 points

selected Apr 30 by Omkar
+1 vote

If you have an Invoke or Init, then you can use something like this:

type Chaincode interface
Init(stub ChaincodeStubInterface) Response
Invoke(stub ChaincodeStubInterface) Response
answered Apr 29 by Rose

Hi @Rose, I am new to this. Can you tell me what I should use in place of Response?

Hi @Kevin. Response could be something like this:

Response
retCode int
payload []byte

Related Questions In Blockchain

0 votes
1 answer
0 votes
1 answer

How to control a malicious user in hyperledger fabric?

Fabric is an implementation of blockchain. Blockchain ...READ MORE

answered Jun 29, 2018 in Blockchain by Omkar
• 65,850 points
125 views
0 votes
1 answer

How to set chaincode path in Hyperledger Fabric?

For chaincode to properly run on your ...READ MORE

answered Jul 27, 2018 in Blockchain by digger
• 27,620 points
333 views
0 votes
1 answer

How to join a peer to a channel in Hyperledger Fabric?

When you run the command: peer channel create ...READ MORE

answered Jul 31, 2018 in Blockchain by digger
• 27,620 points
175 views
0 votes
1 answer
+16 votes
4 answers

© 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.