Variables in Solidity
Explore how to define and use variables in Solidity, including various data types like integers, booleans, and addresses. Understand operators, enums, constants, type conversions, and how Solidity handles integer overflow and underflow errors to write reliable smart contracts.
We'll cover the following...
We can’t write a useful contract without defining variables. In this lesson, we'll learn more about how we can define variables in Solidity, their types, and the operators we can use to manipulate them.
Types
As we’ve learned in the previous lessons, we need to specify a type for state variables, local variables, and function parameters. Let’s see what the main types that we can use in Solidity are:
uint8,uint16, …,uint256: These are unsigned integers from 8 bits to 256 bits in size.int8,int16, …,int256: These are signed integers from 8 bits to 256 bits in size.unit: This is the same asuint256.int: This is the same asint256.bool: This is a boolean value that can either betrueorfalse.fixed: This denotes fixed point numbers of various sizes.address: This is a type representing an Ethereum account address. It can be an address of a smart contract or an address of an externally owned account....