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.

Table of Content

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.

These shortcuts apply to MAC users, but there is also a list for Windows and Linux users.

You can find even more tips and tricks in the official VS Code documentation:

> https://code.visualstudio.com/docs/getstarted/tips-and-tricks

Stay tune ! There is a bonus at the end !

Moving around the code

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 + ←

Go to…


Modifiers are analog to the decorator pattern (source: https://refactoring.guru/design-patterns/decorator)

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.

What is exactly a Modifier in Solidity ?

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).

Modifiers are…


The School Cloackroom by Malcolm Evans, a cartoon drawing used as an analogy to explain mappings in Solidity (taken from https://www.cagle.com/tag/cloakroom/)

Table of Content

  • Introduction to mappings
  • What mappings are used for?
  • How mappings are represented in storage?
  • Key and Values types allowed
  • Operations on Mappings
  • Nested Mappings
  • Mappings as function parameters
  • Structs as value types of mappings
  • Mappings Limitations

Introduction to mappings

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)…


Table of Contents

How are smart contracts created ?

The EVM in Ethereum know that a smart contract is created when an Externally Owned Account (EOA):

  • sends a transaction
  • specifies a zero-address (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?

Let’s first install the solc compiler.

brew update
brew upgrade
brew tap ethereum/ethereum
brew install solidity

To check that solc was installed successfully, run the following command:

solc --version

Let’s create a new file HelloWorld.sol


Table of Contents

Function Visibility

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:

  • internal ones: do not create an EVM call
  • external ones: create an EVM call

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.


Introduction

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.

Array types

In this section, we provide two types of categorisation for arrays:

  • Fixed-size vs dynamic size arrays
  • One-dimensional vs Multi-Dimensional 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.

  • Fixed Size: T[k]
// array that can hold 5 unsigned integers maximumuint[5] my_array;
  • Dynamic Size: T[]
// 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.

Table of Contents

  1. Basic of Structs
  2. How to define a new Struct type?
  3. How to declare a new variable of type Struct?
  4. Struct members types
  5. Structs + Mappings and Arrays = the good mix
  6. Storage, Memory and Calldata with Structs


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.

Table of Content :

  1. Basics of bytes in Solidity
  2. Fixed-size byte arrays
  3. Dynamically-size byte arrays
  4. Bitwise operations in Solidity
  5. An array of bytes = a little difference
  6. Bytes as function arguments
  7. Conversion between addresses and bytes20
  8. Advanced operations with Bytes
  9. A word of warning with Solidity bytes

1. Basics of bytes in Solidity

In computing, the term endianness corresponds to how bytes are ordered (and stored) in a computer or any machine. …

Jean Cvllr

Full Stack Developer, Web / Mobile and Blockchain. https://github.com/CJ42

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store