0

I have a map such as:

mapping (address => bytes32) private myMap;

Later in the code, in a function, I want to ensure my sender already has an entry in that given map.

Can I do this?

require(!myMap[msg.sender], 'there is an entry in the map already!')
2

If the bytes32 value cannot be zero in your app, then:

require(myMap[msg.sender] != bytes32(0x0), "No data.");

To avoid reinventing the wheel, have a look at Are there well-solved and simple storage patterns for Solidity?

This explainer might unpack things in a digestible way: https://medium.com/robhitchens/solidity-crud-part-1-824ffa69509a

Also, while it is admittedly not a great starting point for learning solidity, a general-purpose and reasonably fresh utility over here: https://github.com/rob-Hitchens/UnorderedKeySet

Hope it helps.

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.