As far as I can understand your question, you wish to return some values from a transaction.
Assuming that the transaction is of Invoke Type (not query) then whatever you are returning from the chain code (for example shim.Success(someData);
, it will be part of your transaction payload.)
So, in order to get that transaction payload from the transaction, you have to make sure its committed to the peer's ledger.
To be sure, just before you submit the transaction, you can subscribe to the transaction event using the given transaction id)
Once you receive this event you can be sure that your transaction is successfully committed in the peer.
You can use the same transaction ID you can 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.
[P.S. Assuming you are using Node JS SDK]
EDIT 1:
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.
So, in case you have 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.