I have below data structure used in my solidity code.
// map(address => map(questionId => voted))
mapping(address => mapping(uint256 => bool)) public mapUserVotes;
My requirement is that given an address, I need to check if it 'exists' in this mapping (ie has at least one quesitionId mapped to it).
I understand that all keys do exists in mapping, and maps to 0 by default.
Wanted to understand is there a way to achieve this? Thanks
Best Answer
Mappings initialize with default values, usually a form of 0 (e.g. uint is
0
, address will beaddress(0)
etc.) but there isn't a default "null" for mappings as values. You may need a way to set the status of a user address being initialized. For example:mapping (address => bool)
that it set to true as soon as you add an entry tomapUserVotes
for that address.