0

One of the function in Contract:

 function getPostCounts(uint _postID)public view returns(PostCountsModel memory postCounts){
        return postCountOperations[_postID];
    }

This is the calling function in component.ts (Angular project)

 for (let i = 5; i > 0; i--) {
          app.getPostCounts(i).then(_postCounts => {
            console.log('Iteration-->', i);
            console.log('Total Posts Counts', _postCounts);

          })

The resulting output is::

Iteration--> 5 Total Posts Counts (5) ["0", "0", "0", "0", Array(0), postID: "0", likes: "0", disLikes: "0", shares: "0", comments: Array(0)] Iteration--> 4 Total Posts Counts (5) ["0", "0", "0", "0", Array(0), postID: "0", likes: "0", disLikes: "0", shares: "0", comments: Array(0)] Iteration--> 3 Total Posts Counts (5) ["0", "0", "0", "0", Array(0), postID: "0", likes: "0", disLikes: "0", shares: "0", comments: Array(0)] Iteration--> 2 Total Posts Counts (5) ["0", "0", "0", "0", Array(0), postID: "0", likes: "0", disLikes: "0", shares: "0", comments: Array(0)] Iteration--> 1 Total Posts Counts (5) ["0", "0", "0", "0", Array(0), postID: "0", likes: "0", disLikes: "0", shares: "0", comments: Array(0)]

From the above output we can observe every time it returns the same object. postID is alwys be 0 .I dont know why it is happening.

Please help me!

  • So??? It only implies that keys 1 to 5 in your mapping (or indexes 1 to 5 in your array, you haven't bothered to post your code for some reason, so it's hard to say) are pointing to records which are all but zeros. – goodvibration Jun 17 '19 at 12:35
  • @goodvibration thanks for your answer ..can you please give me the clear explanation. – Suria Jun 17 '19 at 12:58
  • I don't think it can be any clearer than what I already wrote. – goodvibration Jun 17 '19 at 13:05
  • PostID id should returns 5,4,3,2,1 right ?....but even values are zeros but PostID could be different...I store the PostID like increment way... – Suria Jun 17 '19 at 13:09
  • make sure you are calling get on the correct contract address and you need to wait after store until the data is correctly stored in the blockchian, idk which network are you using. to get a better answer provide more infos like which version are you using, which network, your code for store the PostID...etc – Majd TL Jun 17 '19 at 16:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.