Member-only story
Solidity Tutorial: All About Types Conversion
Implicit vs explicit conversion in Solidity, and examples to understand conversion between types.
Note: Solidity is under active development. At the time of writing, this article is valid for Solidity v0.8.x. The next v0.9 release might introduce breaking changes in the type conversions.
If you find any explanations not compatible with v0.9 (once v0.9 has been released), please feel free to highlight the section and report it in comment, so that this article can be kept up to date for the Solidity developer community.
Today's article is quite in-depth, technical and detailed! We explore conversions between different types in Solidity.
We main objective of this article is for you to understand “what is the difference between implicit conversion vs explicit conversion in Solidity”.
We will then cover each possible conversion between types, still using some code examples. So grab a coffee or tea (or a glass of whisky) and let’s get started!
Table of Content
- Implicit vs Explicit — Definition
- Implicit vs Explicit Conversions in Solidity
- Conversion between unsigned integers
uintN
- Conversion between
bytesN
(eg:bytes4
<->bytes16
) - Conversions from
uintM
tobytesN
- Conversion from
bytesN
touintM
- Conversion from
bytes
tostring
- Table Summary —
uintM
← →bytesN
- Literal assignments to
bytesN
- Decimals and Hex Literals assignments
uintN
- Conversion from
bytes
tobytesN
- Conversions to
address
type - Conversion between
address
andaddress payable
- Conversion between
Contract
andaddress
types - References
Implicit vs Explicit — Definition
Before diving into implicit vs explicit conversion in Solidity, let’s first understand the difference in human language.