Skip to content

seanpm2001/Learn-Solidity


/Solidity_logo.svg

Learning Solidity

I am not too experienced with Solidity at the moment, and I do not intend to go further with it. This document will go over my knowledge of the Solidity language.

This document used version 0.8.4 of the Solidity programming language.

Comments in Solidity

Comments in Solidity are the same as comments in languages like C, C++, Java, C#, etc.

// This is a single line comment
/* This is
a multi-
line comment */
/* This is
* also
* a multi-line
* comment */

Break keyword in Solidity

break;

To this day, I am still not entirely sure what the break keyword does, but most languages support it.

/!\ This example has not been tested yet, and may not work

Hello World in Solidity

A hello world program in Solidity is pretty simple. It is not similar to any language I am currently familiar with.

pragma solidity ^0.8.4;

contract HelloWorld {
    function render () public pure returns (string memory) {
        return 'Hello World';
    }
}

Contracts in Solidity

This example is taken from Wikipedia: Solidity (revision 1094734727)

I am only including it as an example, I don't know what it does, or how it works 100% of the way.

// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.4;

contract Coin {
    // The keyword "public" makes variables
    // accessible from other contracts
    address public minter;
    mapping (address => uint) public balances;

    // Events allow clients to react to specific
    // contract changes you declare
    event Sent(address from, address to, uint amount);

    // Constructor code is only run when the contract
    // is created
    constructor() {
        minter = msg.sender;
    }

    // Sends an amount of newly created coins to an address
    // Can only be called by the contract creator
    function mint(address receiver, uint amount) public {
        require(msg.sender == minter);
        balances[receiver] += amount;
    }

    // Errors allow you to provide information about
    // why an operation failed. They are returned
    // to the caller of the function.
    error InsufficientBalance(uint requested, uint available);

    // Sends an amount of existing coins
    // from any caller to an address
    function send(address receiver, uint amount) public {
        if (amount > balances[msg.sender])
            revert InsufficientBalance({
                requested: amount,
                available: balances[msg.sender]
            });

        balances[msg.sender] -= amount;
        balances[receiver] += amount;
        emit Sent(msg.sender, receiver, amount);
    }
}

/!\ This example has not been tested yet, and may not work

Source

The majority of my Soliity knowledge comes from Wikipedia, and this repository

Other knowledge of Solidity

  1. Solidity is a curly bracket language and semicolon language

  2. Solidity is a contract-based language, designed for blockchain contracts. This is the reason why I don't plan to use the language anymore: it is platform-dependant, and bad for the environment.

  3. Solidity uses the .sol file extension (side comment: GitHub is recognizing most of the source code so far as Gerber Image source code)

  4. Solidity is a language recognized by GitHub

  5. Solidity is owned by Etherium

  6. Solidity is a "web3" language

  7. No other knowledge of Solidity at the moment.


File info

Click/tap here to expand/collapse this section

File type: Markdown (*.md *.mkd *.mdown *.markdown)

File version: 1 (2022, Monday, July 4th at 6:12 pm PST)

Line count (including blank lines and compiler line): 182

Current article language: English (EN_USA) / Markdown (CommonMark) / Solidity 0.8.9 / HTML5 (HyperText Markup Language 5.3)

Encoding: UTF-8

All times are UTC-7 (PDT/Pacific Time) (Please also account for DST (Daylight Savings Time) for older/newer entries up until it is abolished/no longer followed)

Note that on 2022, Sunday, March 13th at 2:00 am PST, the time jumped ahead 1 hour to 3:00 am.

You may need special rendering support for the <details> HTML tag being used in this document


File history

Click/tap here to expand/collapse the file history section for this project

Version 1 (2022, Monday, July 4th at 6:12 pm PST)

This version was made by: @seanpm2001

Changes:

  • Started the file
  • Added the title section
  • Added the Learning solidity section
    • Added the Comments in Solidity section
    • Added the Break keyword in Solidity section
    • Added the Hello World in Solidity section
    • Added the Contracts in Solidity section
  • Added the Source section
  • Added the Other knowledge of Solidity section
  • Added the file info section
  • Added the file history section
  • No other changes in version 1