TransWikia.com

How to update multiple values in a mapping without a loop?

Ethereum Asked on November 10, 2021

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.

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP