Published on

Solidity Default Value for the Address Type

Authors

In Solidity there is no concept of null or nil like in many other languages. Instead all types have a default value. Even structs when not initialised have their fields assigned to their default values.

But I struggled to find the default for the address type. I eventually went to ethfiddle and created a contract there where I did not initialise an address field and found that its default is: 0x0000000000000000000000000000000000000000 which is the same as address(0);.

If you need to assign an address in your code through a contract you should make sure that it is not the default value as follows:

function setSomeAddress(address addressYouWantToSet) public {
    require(addressYouWantToSet != address(0))
    ...
}

Then in your Truffle Javascript tests you can force this require to fail using the default value we determined earlier:

someContract.setSomeAddress('0x0000000000000000000000000000000000000000')