Solidity Addresses – Purpose of Address Operators

addressessolidity

According to solidity docs the type address has the following operators:

<=, <, ==, !=, >= and >

Besides checking for equality – Why would I want to check if an address is greater or smaller than another one? What is the usecase?

Best Answer

An address is a 20 byte number, so it gets comparison operators for free: Solidity doesn't have to implement anything, and the gas costs for using them are the same as comparing integers.

In the future, the comparison operators might be useful depending on how in Ethereum works. For example, one of the simplest and early ideas was to shard according to address space, like shard1 contains the first billion addresses, shard2 contains the next billion, and so on. A contract might then use the comparison operators to determine which shard another contract was in.

Related Topic