Is owner > 0x0 a good way to test if an address owner was set in Solidity?
I am not sure if this could break something in the future and if there are better ways to see if the address was set. What is the best solution?

up vote 33 down vote accepted

Though this works, I personally think it is a good idea to have both operand types equal on boolean operations , as you mentioned for future compatibility.

Instead of using > operator use equality == or != , as in case of address the greater operator may not make sense.

Instead of using 0x0 use address(0) or address(0x0), as it would make much more of type of address.

So your code would look like

owner==address(0);// check if the address is not set

Just my 2 cents

  • thanks, what is a Neo Noir Dev? Has it to do with Film Noir? – Roland Kofler Jul 2 '16 at 20:14
  • 6
    Is there documentation for this address(0) somewhere? – JohnAllen Aug 20 '17 at 18:18
  • it merely typecasts uint 0 to an address (0x000...) – Nico Vergauwen Jun 18 at 14:01
  • @JohnAllen as of Nov 2018, it doesn't seem so. – Paul Berg Nov 13 at 8:31

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.