6722/how-to-return-value-from-a-chaincode-in-hyperledger-fabric
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.
Hyperledger Fabric supports only 2 types of transactions on a broader level.
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. 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.
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
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
The peers communicate among them through the ...READ MORE
Fabric is an implementation of blockchain. Blockchain ...READ MORE
For chaincode to properly run on your ...READ MORE
When you run the command: peer channel create ...READ MORE
Summary: Both should provide similar reliability of ...READ MORE
The challenge you are facing is mostly ...READ MORE
No, variables stored by some chaincode (A) ...READ MORE
I know it is a bit late ...READ MORE
It was already decided that installing chaincode ...READ MORE
OR
At least 1 upper-case and 1 lower-case letter
Minimum 8 characters and Maximum 50 characters
Already have an account? Sign in.