Types in Solidity


A boolean is declared with the keyword bool as two possible values true and false.



An integer is declared with the keyword int or uint for unsigned integers. Keywords uint8 to uint256 in steps of 8 (unsigned of 8 up to 256 bits) and int8 to int256uint and int are aliases for uint256 and int256, respectively.

The operators that you can use are similar to traditional programing languages:

  • Comparisons: <=<, ==, !=, >=, > (evaluate to bool)
  • Bit operators: &, |, ^ (bitwise exclusive or), ~ (bitwise negation)
  • Arithmetic operators: +, -, unary -, unary +, *, /, % (remainder), ** (exponentiation), << (left shift), >> (right shift)

Remember that arithmetic operations can lead to integer overflow or underflow, therefore we suggest you use the SafeMath library.


An address is declared with the keyword address. An address define where you can find a contract or an account on the blockchain.

When you interact with a contract, you can know who interacts with the contracts by accessing msg.sender.

See how we use an address to add basic right privileges to a contract.


An enum is declared with the keyword enum. It’s a way to create a user-defined type in Solidity. They are explicitly convertible to and from all integer types but implicit conversion is not allowed. The explicit conversions check the value ranges at runtime and a failure causes an exception.



Leave a Comment