Photo by GuerrillaBuzz Crypto PR on Unsplash
Solidity for beginner part 1
Best intro to solidity for beginners
Table of contents
No headings in the article.
In this article I will break down solidity language which people believe to be difficult to understand.
The platform we will use for the running and compiling of the solidity code will be remix.
create a file mike.sol
All our codes will be saved inside this file
Solidity code starts with what we called pragma solidity, then you state the version of the compiler that you want to use to compile. For example it can be
pragma solidity 0.5.0;
The above code means that you are using the compiler version 0.5.0 while the semicolon helps in terminating the line.
Saying specifically version 0.5.0 is limiting your solidity code, so you need to use version 0.5.0 and above and that can be achieved by using the code below.
pragma solidity ^0.5.0;
The above means that you are working with compiler 0.5.0 and above, up to the latest version of compiler on remix.
Contract in solidity
Contract declaration is very important in solidity. Note: All functions and variables are to be declared inside a contract.
This is an example of a contract in solidity:
pragma solidity ^0.5.0;
contract Michael{
}
In the above code, we declared the compiler version followed by the contract. This is the format for creating a contract.
contract name-of-contract{
}
Comment in solidity Just like other programming language that you know, commenting is important in order to make your code readable.
There are different methods of commenting in solidity.
- Inline commenting
- Multi line commenting
Let discuss the first one which is inline commenting.
- Inline commenting is a way of commenting a particular line of code in solidity.
It is denoted by double forward slash
//
for example
pragma solidity ^0.5.0;
contract Michael{
//our code is here
}
In the code above, the "our code is here" is commented out and solidity will not read it as a code because of the two forward slashes that appears before it.
2 Multi-line commenting In this method, we are commenting more than one line of code for example
pragma solidity ^0.5.0;
contract Michael{
/*
When we talk about multi-line commenting
this is what we mean.
We can comment two or more lines of code.
*/
}
Here is the whole overview of the commenting.