In solidity every variable is set to 0 by default.

You should think of mappings as all possible combinations are set to 0 by default.

In your specific case I would use the following:

if (buyers[msg.sender].amount == 0)
Answer from Viktor Tabori on Stack Overflow
🌐
Blackadam
blackadam.hashnode.dev › zero-address-check-the-danger
The Danger of not checking for address zero in smart contract.
January 4, 2023 - In Solidity, the zero address (also known as the null address) is a special address that represents an uninitialized or burn address. It is represented as 0x0 or 0x0000000000000000000000000000.
🌐
CoinsBench
coinsbench.com › what-is-address-0-or-null-address-in-solidity-03df1d4ee65d
What is Address(0) or Null Address in Solidity? | by Aapsi Khaira | CoinsBench
April 30, 2024 - It serves as a placeholder for uninitialized or burn addresses, symbolizing a void where tokens vanish into the ether, never to return. It is exactly how default assignment works in any other programming language, being either zero or null values. // SPDX-License-Identifier: MIT pragma solidity ...
🌐
Metaschool
metaschool.so › home › answers › what is address(0) in solidity
What is Address(0) in Solidity -
March 29, 2024 - This address holds a distinctive status within the Ethereum ecosystem, signifying a null address with all its bytes set to zero. This special address possesses no Ether balance and is incapable of sending or receiving transactions.
🌐
Medium
medium.com › @joichiro.sai › solidity-attack-vectors-11-no-address-zero-check-7dd337bd9587
Solidity Attack Vectors #11 — No Address Zero Check | by 0xjoi | Medium
February 1, 2025 - For example, if a transaction sends Ether or tokens to the Zero Address, those funds become permanently inaccessible. ... // SPDX-License-Identifier: MIT pragma solidity ^0.8.7; contract Database { struct User { address userAddress; string name; ...
🌐
Etherscan
etherscan.io › address › 0x0000000000000000000000000000000000000000
Null: 0x000...000 | Address: 0x00000000...000000000 | Etherscan
This address is not owned by any user, is often associated with token burn & mint/genesis events and used as a generic null address
Find elsewhere
🌐
Readthedocs
solidity.readthedocs.io › en › v0.5.3 › types.html
Types — Solidity 0.5.3 documentation
June 9, 2022 - In addition, types can interact with each other in expressions containing operators. For a quick reference of the various operators, see Order of Precedence of Operators. The concept of “undefined” or “null” values does not exist in Solidity, but newly declared variables always have ...
Top answer
1 of 4
51

Within an Ethereum transaction, the zero-account is just a special case used to indicate that a new contract is being deployed. It is literally '0x0' set to the to field in the raw transaction.

Every Ethereum transaction, whether it's a transfer between two external accounts, a request to execute contract code, or a request to deploy a new contract, are encoded in the same way. A raw transaction object will look something like this:

transaction = {
  nonce: '0x0', 
  gasLimit: '0x6acfc0', // 7000000
  gasPrice: '0x4a817c800', // 20000000000
  to: '0x0',
  value: '0x0',
  data: '0xfffff'
};

If to is set to something other than '0x0', this request will result in transferring ether to the address (if value is non-zero), and execute the function encoded in the data field. Remember, the address can either be a contract or an external account.

When the to address is the zero-address, a new contract will be created by executing the code in data (this is what is meant by "code that returns the code"). The address of the newly created contract is technically known beforehand as it's based on the address of the sender and it's current nonce. That address becomes the official address of the contract after mining.

For a pretty good read on Ethereum transactions, check out this blog post.

Note: There is also the actual Solidity code statement address(0) which is the initial value of a variable of type address. The documentation you posted, however, is referring to specifically when the to account address in a transaction is set to '0x0'.

2 of 4
14

It's not actually true that a contract creation transaction has a "to" field set to the zero address (meaning 0x00...000). This is an easy mistake to make (and I've made it too) as it is described that way in many resources.

The passage you cite from the Solidity docs were updated to state this:

If the target account is not set (the transaction does not have a recipient or the recipient is set to null), the transaction creates a new contract. As already mentioned, the address of that contract is not the zero address but an address derived from the sender and its number of transactions sent (the “nonce”).

So you can see they realized at some point that the recipient field should be empty. I've actually looked at serialized creation transactions and found 0x80 there instead of an RLP-ed zero address.

In fact, 0x80 is the RLP encoding of an empty byte array, which is what the Yellow Paper states is the recipient for a contract creation:

The address hash $T_t$ is slightly different: it is either a 20-byte address hash or, in the case of being a contract-creation transaction (and thus formally equal to ∅), it is the RLP empty byte sequence and thus the member of $B_0$

As I said, this is a common source of confusion. In that vein, this GitHub PR rolling back a mistakenly "fixed" test is amusing. It has the comment:

RLP encoding of 0 is encoding of empty byte array, so 0x80 is correct.

0x00 is encoding of byte array of length 1 containing one byte 0, not encoding of integer 0.

🌐
Stack Exchange
ethereum.stackexchange.com › questions › 44597 › ecrecover-in-solidity-returning-null-address
go ethereum - ecrecover in solidity returning null address - Ethereum Stack Exchange
April 3, 2018 - Now the problem has changed to returning a 0x address, ... Thanks for correcting my carelessness. But the issue still remain after I corrected it. It still returns null.
🌐
Better Programming
betterprogramming.pub › absence-of-null-in-solidity-bc80ce5e5b09
Absence of Null in Solidity
September 2, 2022 - Absence of Null in Solidity Solidity programming language doesn’t have the nullability feature One of the weirdest Solidity programming language’s quirks is the absence of null. Coming from …
🌐
Medium
jeancvllr.medium.com › solidity-tutorial-all-about-addresses-ffcdf7efc4e7
Solidity Tutorial : all about Addresses | by Jean Cvllr | Medium
April 10, 2026 - Basic of Addresses in Solidity & address literals · Address vs address payable · Methods available with addresses (including call(), delegatecall() and staticcall() ) Types conversions between addresses and address payable · Methods returning an address type ·
🌐
Solidity
docs.soliditylang.org › en › latest › types.html
Types — Solidity 0.8.36-develop documentation
In addition, types can interact with each other in expressions containing operators. For a quick reference of the various operators, see Order of Precedence of Operators. The concept of “undefined” or “null” values does not exist in Solidity, but newly declared variables always have ...
🌐
GitHub
github.com › tronprotocol › java-tron › issues › 6066
What does address(0) mean in solidity? · Issue #6066 · tronprotocol/java-tron
November 4, 2024 - What does address(0) mean in solidity?#6066 · Copy link · Labels · type:docs · abn2357 · opened · on Nov 4, 2024 · Issue body actions · Anyone can give me a detailed explanation? When to use it and what its functions are. Reactions are currently unavailable ·
Author   tronprotocol
🌐
Edureka Community
edureka.co › home › community › categories › blockchain › are there null like thing in solidity
Are there null like thing in solidity | Edureka Community
September 21, 2018 - struct buyer{ uint amount; Status status; } mapping(address=>buyer) public buyers; mapping(uint=> ... to tell whether a buyer is in the mapping
🌐
Solidity
docs.soliditylang.org › en › v0.8.11 › types.html
Types — Solidity 0.8.11 documentation
April 14, 2022 - In addition, types can interact with each other in expressions containing operators. For a quick reference of the various operators, see Order of Precedence of Operators. The concept of “undefined” or “null” values does not exist in Solidity, but newly declared variables always have ...
🌐
Stack Overflow
stackoverflow.com › questions › 65779542 › solidity-return-null-value
Solidity return null value - Stack Overflow
January 18, 2021 - function isPrestataire(address checkAdresse) private view returns (bool, prestataire) { for (uint i = 0; i < prestataires.length; i++) { if (prestataires[i].getAccount() == checkAdresse) return (true, prestataires[i]); } return (false, null);//fails // return (false); fails also }