DEV Community

Cover image for Learn Solidity with me
Virendra Khorwal
Virendra Khorwal

Posted on

Learn Solidity with me

Let's start

I am learning Solidity from freeCodeCamp and Solidity Official Documentation. As I learn some new concept I will try to explain to you. This will help me to understand it easily and also maybe you. If you feel something missing comment below. And feel free to ask any queries. All help each other and learn together.

Basics

I will first begin with the different types or data types in Solidity. There are different types in solidity.

Integer

  • int8 to int256 (8 steps) like int16, int24 etc.
  • uint8 to uint256 (8 steps) like uint16, uint24 etc.

int are signed integers and uint are unsigned integers. int256 and int are same. Similarly, uint256 and uint are also same. Or int is alias for int256 and uint is alias for uint256.

Address

There are two address types. One is address and another is address payable. The size of address is 20bytes same as the size of Ethereum Address. address payable is same as address but it have some additional information like transaction and send. We can implicitly convert address payable to address. But conversion from address to address payable done explicitly using payable(<address>)

Fixed Point Number

! Not fully support yet

We can declare fixed point number using fixed and ufixed. But can't assign to or from.

We will discuss how to perfrom operation on these types and other types in another blog.
Let's discuss the structure of a contract.

Structure of Contract

If you are familiar with object oriented programming like C++, Java then you can find contract is similar like classes in these object oriented programming.

contract SimpleStorage {
    // Code
}
Enter fullscreen mode Exit fullscreen mode

A contract can contain -

  • State Variables
  • Functions
  • Function Modifiers
  • Events
  • Errors
  • Struct Types
  • Enum Types

State Variables are variables which permanently stored in contract. They store the state of that variable like

contract SimpleStorage {
    uint storeValue; // state variable
}
Enter fullscreen mode Exit fullscreen mode

Struct Types are user defined or custom defined types which includes several types.

contract SimpleStorage {
    stuct Store {
        uint height;
        bool adult;
        address delegate;
        int number;
    }
}
Enter fullscreen mode Exit fullscreen mode

Similar is Enum types but have finit set of constant values

contract SimpleStorage {
    enum Store {Created, Seated, Locked}
}
Enter fullscreen mode Exit fullscreen mode

We will discuss Function, Function Modifies, Events Errors in another blog.

Top comments (0)