Solidity Bytes – How to Check If a Bytes Variable Is Empty

bytessolidity

I have a mapping in my smart contract with bytes32 keys and bytes values. How can I check if bytes value exists for specific key?
Mapping is something like this:

mapping(bytes32 => bytes) public Countries;

Best Answer

You can check it via .length. It will be 0 if it is empty/uninitialised.

Countries[key].length
Related Topic