Variables in Solidity

Learn about defining variables and operations in Solidity.

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 as uint256.

  • int: This is the same as int256.

  • bool: This is a boolean value that can either be true or false.

  • 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.

  • ...