Initializing, Emptying, and Checking for Empty Address and Bytes Data Types in Solidity

Address Data Type

In Solidity, there is no concept of undefined or null values, but newly declarde variables have corresponding default values.

The address type is a 20-byte data type, 160 bits or 20 bytes in size, with a default value of 0x0 (the zero address). It is used to store Ethereum account addresses.

Default Value and Operations

// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.9.0;

contract AddressDemo {
    address public defaultAddr;        // default value is address(0)
    address public emptyAddr = address(0); // explicitly set to empty

    // Check if an address is empty (zero address)
    function isEmpty() public view returns (bool) {
        return defaultAddr == address(0);
    }

    // Check if two addresses are equal
    function isEqual() public view returns (bool) {
        return defaultAddr == emptyAddr;
    }
}

Remix Results (requires internet connection):

Address default value in Remix Address equality check in Remix

Bytes Data Types

Solidity has several byte data types. Fixed-size byte arrays range from bytes1 to bytes32, while dynamic byte arrays are declared as bytes. Their default value is an empty byte sequnece (""), not 0x0 or "0x0" (which would cause an error).

Bytes default values in Remix

// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.9.0;

contract BytesDemo {
    bytes1  public b1;   // default: empty
    bytes8  public b8;   // default: empty
    bytes32 public b32;  // default: empty
    bytes   public dynamicBytes;          // default: empty
    bytes   public emptyBytes = "";       // explicitly set to empty

    // Check if a bytes array is empty (length 0)
    function isEmpty() public view returns (bool) {
        return dynamicBytes.length == 0;
    }

    // Check if two non-empty bytes are equal
    function isEqual() public view returns (bool) {
        bytes memory a1 = "75048074384425574039e8f";
        bytes memory a2 = "75048074384425574039e8f";

        if (a1.length != a2.length) {
            return false;
        }
        for (uint256 i = 0; i < a1.length; i++) {
            if (a1[i] != a2[i]) {
                return false;
            }
        }
        return true;
    }
}

Remix Results:

Bytes equality check in Remix Bytes is empty check in Remix

Tags: solidity address bytes data type default value

Posted on Thu, 11 Jun 2026 16:57:59 +0000 by kristoff