Search code examples
ethereumsolidity

Check that object is null in solidity mapping


I have this solidity mapping

mapping (string => Ticket) public myMapping;

I want to check if myMapping[key] exists or not. How can I check?


Solution

  • The entire storage space is virtually initialized to 0 (there is no undefined). So you have to compare the value to the 0 value for your type. For example, mapping[key] == address(0x0) or mapping[key] = bytes4(0x0).