3 - Solidity basis

What is Solidity ?

  • Solidity is an object-oriented, high-level language for implementing smart contracts. It is designed to target Ethereum Virtual Machine(EVM)
  • It is a compiled language. The source code with a .sol extension can be compiled to hex-serialized binary using the solc compiler.
  • It uses an ABI to define how data structures and functions are accessed in machine code (it is specified as a JSON array of function descriptions and events)
  • It is statically typed: bool, int256/uint256, fixed/ufixed, address, arrays, map
  • It supports inheritance, libraries and complex user-defined types and scopes using keywords: struct, inheritance, modifier, private, public.
  • It implements primitive functions like crypto or time and it uses a logging mechanism based on events

Example of Faucet.sol

// SPDX-License-Identifier: CC-BY-SA-4.0

// Version of Solidity compiler this program was written for
pragma solidity 0.6.4;

// Our first contract is a faucet!
contract Faucet {
    // Accept any incoming amount
    receive() external payable {}

    // Give out ether to anyone who asks
    function withdraw(uint withdraw_amount) public {
        // Limit withdrawal amount
        require(withdraw_amount <= 100000000000000000);

        // Send the amount to the address that requested it

Note that Solidity offers a compiler directive known as a version pragma that instructs the compiler that the program expects a specific compiler (and language) version. Let’s look at an example: pragma solidity ^0.6.0;

$ solc --optimize --bin Faucet.sol
======= Faucet.sol:Faucet =======
$ solc --abi Faucet.sol
======= Faucet.sol:Faucet =======
Contract JSON ABI
[{"inputs":[{"internalType":"uint256","name":"withdraw_amount","type":"uint256"}], \
"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"}, \

To learn Solidity, we recommend to start with this video guide 🎬 [01:39:10].

You can also try some examples πŸ“– and this interactive tutorial named Cryptozombies πŸ“–.

And read the full documentation πŸ“– and have a close look to the style guide πŸ“–.


In this lesson, we learn the solidity basis to develop Smart Contract. Next lesson is an hands-on to apply those concepts.