0

I am trying to read a lot of data from a smart contract mapping, How can I include pagination when retrieving data through smart contract methods?

3

It would not be efficient to do pagination in smart contract, it can be done on client side:

If you have mapping, most probably you have list of keys, something like:

uint count;
mapping(bytes32 => entry) entries;
bytes32[] keys;

Then you need:

  • retrieve count
  • calculate amount of pages from overall amount
  • retrieve keys keys[i], ... for specified page
  • retrieve entries entries[keys[i]], ... for specified page

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.