1

if you have a mapping like:

mapping (uint => bool) owned;

How would you go through and update 1000 items in that mapping to set them all to true?

Without using a loop due to gas prices.

Is there a way to do this?

Is there another way with another structure besides maps? Arrays? mapping to a struct?

An example might be - I want to set items 500 - 1,500 to true and the rest are false. How would you achieve this?

edit: a good example would be batch minting ERC-721 tokens. How would you create 1000, or 20k tokens? You obviously can't do a loop to update the owner mapping.

3
  • How many are "the rest"? – goodvibration Jul 21 '20 at 16:49
  • Strictly answering your question - there is obviously no way which is more efficient than iterating. However, if you explain your use-case then there might be a different design altogether, which could possibly allow you to improve the efficiency of your code. – goodvibration Jul 21 '20 at 16:53
  • I updated with another example - the rest would be anything not included. A good example is a ERC-721 token creation. Such as the owner mapping - where you need to store a uint to an address. How would you update that mapping to give them 1000 tokens? – Zach Jul 21 '20 at 16:58

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.