There is huge potential when it comes to blockchain technology, especially when it comes to the development of decentralized applications (Dapps).
Anyone who’s new to blockchain technology, has a knack for programming, or is simply interested in engaging with programming for it, should start studying Solidity. It is important, however, to know if Solidity is Suitable for Dapps development and if it is suitable for your specific interests.
As such, with a better impression of all of the things that make up the architecture of Solidity, you should also look at examples and dedicate a lot of time to learning them.
It is important to know how to get started with Solidity, so you do not get lost along the way. As such, we will provide you with a Solidity for beginners detailed overview of Solidity and other related aspects such as types, functions, events, and so on. You will also see some of the flexibility that this language brings to the table.
Before Getting Started
When it comes to learning a new skill or a new programming language, you can get overwhelmed with what direction you might need to take. It is important to remember to just carry on with the process.
Here are some of the things that you need to understand prior to starting the programming journey.
- You need to understand the fundamentals through reading the Bitcoin Whitepaper as well as the Ethereum Whitepaper.
- You need to watch a few videos online on What is Bitcoin and What is Ethereum, even if you fully understand them, just to get updated information as well as a refresher about all of their current developments.
- You can also look into beginner ERC20 or ERC721 tutorials, as well as company project documentation.
Solidity Compiler Installation
The important role that Solidity plays in Smart contracts and dApp development requires an environment for Solidity to function well on. The common methods for installing this will provide you a detailed overview of how it works. Here are some different methods when it comes to setting up a Solidity environment, each of which has its own unique quirk.
Here we have versioning or semantic versioning. The different versions of Solidity abide by semantic versioning with the facility of nightly development builds as well as associated releases. These do not guarantee functionality but include undocumented and broken modifications, or at least they can include this.
Remix is a recommended tool that you will find across many Solidity tutorials to learn quickly about it. It offers an online integrated development environment or IDE for writing Solidity smart contracts, which is followed by deploying and running them.
Here, you get access to the Remix IDE online without needing to make any additional installations, and furthermore, it will also allow you to use it offline with options such as evaluating nightly builds without the installation of multiple versions of Solidity. It also has a command-line Solidity compiler.
Then you can find Hardhat. Hardhat helps developers to manage and automate the common tasks of the process of building smart contracts and Dapps, as easily introducing more functionality around this workflow. That means you can compile, run and test smart contracts at the very core.
It focuses on solidity debugging, presents explicit stack traces and error messages when transactions fail. Hardhat comes built-in with Hardhat Network, a local Ethereum network designed for development, and a CLI to interact with the core functionalities.
Example of he Hardhat CLI:
Alternatively, you can work with Truffle, which is a development environment, testing framework, and asset pipeline for blockchains using the Ethereum Virtual Machine (EVM). With it you get a lot of important characteristics that make it easier to develop Dapps like an interactive console for direct contract communication, network management to deploy to any public and private network, contract compilation, linking, and binary management.
Another part of the Truffle ecosystem is Ganache a local Ethereum blockchain for test solidity contracts, you can use Ganache in two different ways: you can use the Ganache CLI (the most complete version) or you can use the Ganache UI (the most friendly version especially for beginners).
What Are the Basics of Solidity?
In its simplest form, Solidity is a programming language intended to assemble smart contracts utilized in the Ethereum blockchain. It is statically formulated in order to uphold essential elements such as libraries and legacy.
The solidity language supports general value types such as:
- Booleans – This returns a true or a false value, and the logical operators include: “!” which is a logical negation, “&&” which is logical conjunction (and), “||” which is a logical disjunction (or), “==” which is equality and “!=” which is inequality.
- Integers – Solidity supports the int or unit for both unsigned and signed integers.
These storage allocations can be of various sizes; for example, keywords such as uint8 and uint256 can be used to allocate a storage size of 8 bits to 256 bits. By default, however, all allocations are 256 bits. These operators are also compatible with integer data types such as comparisons which are <=, <, ==, !=, >=, >. These are used to evaluate bool. Then you have bit operators that are: &, |, ^ bitwise exclusive ‘or’, ~ bitwise negation, “not”.
Then you have arithmetic operators: +, – , unary -, unary +, *, /, % remainder, ** exponentiation, << left shift, >> right shift.
- Address – This is an address that can carry up to a 20-byte value.
- String Literals – String literals are depicted using double or single quotes. They imply training value zeroes.
- Modifier – Modifiers ensure the fulfillment of any predefined conditions before the code execution occurs.
- Mappings – These mappings return values that are related to a given storage site.
Note that Solidity also provides basic arrays, enums, operators, and hash values that allow you to create a data structure known as “mappings,” These can be used to return values associated with a given storage location. An array is a contiguous memory allocation of size, which you, the developer, define, where if the size is initiated as K and the element as T, the array can be written as T[k].
These arrays can also be dynamically instantiated using the notation unit [][6], where here the notation initializes a dynamic array with six contiguous memory allocations.
Furthermore, you also have the opportunity to have a two-dimensional array that can be initialized as arr[2][4], where the two indices point towards the dimensions of the matrix.
Now that you have a perspective of some of the generic value types keep in mind that they can be further integrated to develop much more complex data types.
Furthermore, you need to be aware of the reserved keywords in Solidity, all of which play a role and are an important requirement when it comes to using it. Knowing these keywords is an essential part of it that will help you better understand the language.
- Abstract
- Auto
- Alias
- Default
- Reference
- Try
- Static
- Define
- After
- Switch
- Case
- Immutable
- Typeof
- Override
- Sizeof
- Unchecked
- Typedef
- Inline
- Copyof
- Apply
Getting Started with Solidity Programming
You probably have a clearer perspective as to how all of this works at this point in time. That being said, the simplest way to get a feel for the language is to actually start writing it.
In this example, the chosen compiler is the Remix IDE, and this should give you a clearer perspective of how all of this works.
- Once you write this code down, you can select the Compile tab and click on Start to Compile.
- You need to see the Run tab, where you can click on the Deploy button.
- You have to open the drop-down menu and select Solidity Test at 0x.
- You can click on the getResult button and display the output of the code written in the solidity language.
Then you have comments. Any type of text between the characters ‘/*’ and ‘*/’ is referred to as a comment. Any type of text found between the ‘//’ and the end of a line is also referred to as a comment. The solidity compiler ignores this text.
Taking an In-Depth Look at Variables
With all of that out of the way, we need to take a look at variables.
There are three types of variables in Solidity.
- State Variables – the ones that have their values stored permanently in cold storage.
- Local Variables – the ones that have their value present for the course of the execution of the function.
- Global Variables – the special variables that are present in the global namespace and can help in the process of gaining information regarding the blockchain.
Example of a state variable:
Example of a local variable:
Global variables obtain information. Here is an outline of them, as well as their functions:
- blockhash(uintblockNumber) returns (bytes32): Represents hash of the concerned block, however it only works for the 256 latest blocks while ignoring current blocks.
- block.coinbase (address payable): Shows the address of the current block miner.
- block.difficulty (uint): Points out the difficulty of a block.
- block.gaslimit (uint): Shows the gaslimit of the current block.
- block.number (uint): Shows the current block number.
- block.timestamp (uint): Displays the timestamp of current block in terms of the seconds passed since the unix epoch.
- msg.sig (bytes4): Through it, you can find out the first four bytes of the function identifier or calldata.
- msg.data (bytes calldata): Shows the complete call data.
- now (uint): You can find the information of the current block timestamp.
The Bottom Line
There is a lot more when it comes to learning Solidity and getting a handle on it, however, these are just the basics that you need to know in order to get started and potentially build your Dapps in no time. You can review the official Solidity documentation here, where you can truly get an in-depth look at everything else.