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,500 points
2,944 views

2 answers to this question.

+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 IDYou 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
• 17,100 points

selected May 1, 2019 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, 2019 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
• 69,220 points
1,058 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
• 26,740 points
1,857 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
• 26,740 points
2,079 views
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
1,444 views
+15 votes
5 answers
+16 votes
4 answers
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP