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?


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
  • It is possible to go out of gass when call whole bytes32[], even if few millions keys are in array? Jan 31 '20 at 17:40

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.