0

I have a mapping that store an hash from all smart contract transactions (NFT tokens).

For every transactions, I need to check if the hash function is NOT in my mapping. If it's NOT in the mapping, I add my hash in it (20k gas cost?) and execute transactions.

My question is : does the "checking" increase gas cost if I have 5000 entries in my mapping? And 10000 entries?

3
  • How are you 'checking' if the hash is in the mapping? Accessing a single mapping value should be constant.
    – Ismael
    Jun 2 '21 at 6:18
  • I need to compare a hash in a mapping. If there is 1000 hash stored and I must NOT found my hash in this mapping I need to compare hash to ALL mapping entries.
    – GrindCode
    Jun 2 '21 at 17:18
  • Accessing a single item should cost the same if you have 1 or 1M items, but if you have to iterate over all inserted items it will cost proportional to the number of items. In any case if you use keccak hashes as keys for the mapping then having duplicates has a very low probability, since it will be equivalent to find a keccak collision.
    – Ismael
    Jun 2 '21 at 17:41

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.