Welcome to All About Solidity, an article series that aim to help smart contracts developers, building applications on top of the Ethereum blockchain.
It consists of a series of articles that cover several aspects of the Solidity smart contract language, such as addresses, mappings, bytes, structs and more…
This page is the main entry point to the article series. You will find below a complete list of all the articles.
Feel free to leave a comment or a clap, if you like the article and found them useful, to give any feedback or report errors.
Enjoy your reading !
In this article, you will find some very useful keyboard shortcuts that aim to make writing code in VS Code more easily, quickly and safely.
You can find even more tips and tricks in the official VS Code documentation:
Stay tune ! There is a bonus at the end !
Go to Beginning of Line: CTRL + A
Go to End of line: CTRL + E
Go to Beginning of code (first character) in this line: CMD + ←
In Solidity, Modifiers express what actions are occurring in a declarative and readable manner. They are similar to the decorator pattern used in Object Oriented Programming.
The Solidity documentation define a modifier as follow:
A function modifier is a compile-time source code roll-up.
It can be used to amend the semantics of functions in a declarative way.
From this definition, we can understand that a modifier aims to change the behaviour of the function to which it is attached.
For instance, automatically checking a condition prior to executing the function (this is mainly what they are used for).
Mappings in Solidity are similar to the concept of hash map in Java or dictionary in C and Python. They act like hash tables, although they are slightly different.
There is nothing better than an analogy with the real world to understand what are mappings in Solidity and how they behave. The following example was taken from a Reddit post.
A hashmap (= mapping)…
The EVM in Ethereum know that a smart contract is created when an Externally Owned Account (EOA):
0x0000000000000000000000000000000000000000) as a recipient.
The data field of the transaction contain the compiled bytecode of the smart contract written in Solidity.
Do you want to see what does this data field / bytecode looks like?
brew tap ethereum/ethereum
brew install solidity
To check that
solc was installed successfully, run the following command:
Let’s create a new file
Solidity is a high level language for the EVM. The EVM under the hood does what we call EVM calls, known as “message calls”. From a higher perspective, Solidity knows two kind of function calls:
There are 4 main visibilities that can be assigned to functions in Solidity.
Let’s look at them in more details:
public : visible everywhere (within the contract itself and other contracts or addresses).
Therefore, it is part of the contract interface (ABI). It can be called internally or via messages.
Any program written in a high level language like C, Go, or Java is first compiled down to what is called an assembly language, before it is executed. But what is assembly?
Assembly ( also called assembler language ) refers to any low-level programming language that is converted to machine code using an assembler. Assembler languages are tied to either a physical or a virtual machine, because they implement its instruction set. An instruction tells simply the CPU to do some fundamental task, such as adding two numbers
Examples of processors are the Intel x86 or ARM. Intel x86 has…
In Solidity, an
array is an ordered list of items that is indexed numerically, starting at 0.
In this section, we provide two types of categorisation for arrays:
The Solidity documentation make the distinction between fixed-size and dynamic size arrays. In the examples below,
T is the element type and
k is the array length / size. If
k = 5 , the array can hold a maximum of 5 values.
// array that can hold 5 unsigned integers maximumuint my_array;
// array containing…
Structs are a way to define new custom types in Solidity. The Solidity documentation define them as “objects with no functionalities”, however, they are more than that.
Like in C, structs in Solidity are a collection of variables (that can be of different types) under a single name.
This enable you to group many variables of multiple types into one user defined type.
Bytes are easy to work with in Solidity because they are treated a lot like an array. You can just decode the bytes in the frontend and less data is stored on the blockchain.
In computing, the term endianness corresponds to how bytes are ordered (and stored) in a computer or any machine. …