How to read a state after writing it into a chaincode?

0 votes

I have setup the Fabric as per the instruction using docker and everything works fine. I have a chaincode which stores a value in the world state which I can read afterwards using a query method. When I submit multiple separate requests within a short period of time to store different data in the world state, I need to read th data submitted previously within each request. However, I am unable to read the most recently submitted data.

So I am wondering if there is any way to read the previous data just after storing the subsequent data.

May 28, 2018 in Blockchain by Christine
• 15,790 points
224 views

1 answer to this question.

0 votes

Data that is 'written' in chaincode is not yet committed to the database, it is only a proposal to write something to the database at that point. So, waiting a few seconds in the chaincode would not be sufficient. Only committed data is read back in chaincode. Therefore after you make an update in chaincode and get the proposal response, you must submit the transaction to ordering. Only then can the data be read back in chaincode.

However, If you must read the data that you just wrote within the same chaincode function, then you will need to keep a map of the data that has been written and retrieve the value from the map rather than from the committed database.

Hope this helps :)

answered May 28, 2018 by Perry
• 17,010 points

Related Questions In Blockchain

0 votes
1 answer

Hyperledger Composer: How to update a contract after it is saved?

Try this and see if this works: /** * ...READ MORE

answered Nov 9, 2018 in Blockchain by Omkar
• 67,290 points
32 views
0 votes
1 answer

In a Blockchain, how difficult is it to modify the third to last block?

Technically, it's not difficult at all, all ...READ MORE

answered Apr 20, 2018 in Blockchain by Christine
• 15,790 points
61 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
+1 vote
1 answer

Hyperledger - How can I use transaction certificates to enforce privacy?

The transaction certificates don't actually address privacy ...READ MORE

answered Apr 17, 2018 in Blockchain by Perry
• 17,010 points
113 views
+1 vote
2 answers

How to return value from a chaincode in Hyperledger Fabric?

Hyperledger Fabric supports only 2 types of ...READ MORE

answered Jun 13, 2018 in Blockchain by Perry
• 17,010 points
763 views