How can I check if an Contract variable is undefined in Solidity?

2 Answers 2


According to this

Memory-stored objects as local variables are correctly zero-initialised: Members of structs and elements of fixed-size arrays are recursively initialised, dynamic arrays are set to zero length. delete x assigns a new zero-initialised value to x.

There is no such undefined variable. All objects are zero-initalised.


By some Solidity coding conventions you add a boolean 'valid' element to any struct to indicate it is undefined (false is the initialized value).

Sometimes I see fields having zero reserved to mean undefined - e.g. treat 0 as an undefined address. You could also do that for a string, but string is often externally input so you have to make sure someone didn't send you a zero string.

I would advise using a field where zero is naturally meaningful like a separate bool or an existing address element in a struct.

  • 1
    This is not useful for a pure Contract object isn't it? Commented Mar 31, 2016 at 14:31
  • what do you mean by a "pure Contract object"?
    – Paul S
    Commented Mar 31, 2016 at 19:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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