Giter VIP home page Giter VIP logo

seanpm2001 / learn-solidity Goto Github PK

View Code? Open in Web Editor NEW
2.0 3.0 1.0 556 KB

A repository for showcasing my knowledge of the Solidity programming language, and continuing to learn the language.

Home Page: https://github.com/seanpm2001/Learn/

License: GNU General Public License v3.0

Solidity 100.00%
article collection education gpl3 gplv3 learn-solidity md seanpm2001 seanpm2001-education seanpm2001-life-archive

learn-solidity's Introduction


/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

learn-solidity's People

Contributors

seanpm2001 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

seanwallawalla

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.