Skip to main content

Command Palette

Search for a command to run...

Address in Solidity

Published
1 min read
Address in Solidity

The address type comes in two categories:

  • Address: A 20-byte value (the size of an Ethereum address).

  • Address payable: The same as the address but with the extra members transfer and send

This difference is made because a simple address is not designed to receive Ether, for example. After all, it is a smart contract that was not built to accept Ether.

Type conversion:

Conversions from address payable to address are allowed implicitly but must be done explicitly through payable(<address>).

uint160, integer literals, bytes20, and contract types support explicit address conversions.

Only address and contract-type expressions may be explicitly changed to address using the explicit conversion payable (...). This conversion is only permitted if the contract can receive Ether, i.e. The contract has a receive or payable fallback method. payable (0) is an exception to this rule.

Important: If you need a variable of type address and plan to send Ether to it, then declare its type as address payable to make this requirement visible. Also, try to make this distinction or conversion as early as possible.

Address Operators:

  • <=

  • <

  • \==

  • !=

  • \>=

  • \>

For more content, follow me on - https://linktr.ee/shlokkumar2303

More from this blog

S

Shlok Kumar's blog

112 posts