Decentralized Programmer: Solidity 101

in #solidity6 years ago (edited)

Solidity primer

What is solidity?

Solidity is a contract-oriented, high-level language for implementing smart contracts. It was influenced by C++, Python and JavaScript and is designed to target the Ethereum Virtual Machine (EVM). Solidity is statically typed, supports inheritance, libraries and complex user-defined types among other features.

Source: https://solidity.readthedocs.io/en/v0.4.25/

Best IDE

Remix: http://remix.ethereum.org

Smart contracts basics

pragma solidity ^0.4.0; //Version of solidity

contract SimpleStorage {
    uint storedData;

    function set(uint x) public {
        storedData = x;
    }

    function get() public view returns (uint) {
        return storedData;
    }
}

Explanation:

pragma solidity ^0.4.0 Version of solidity

contract SimpleStorage Contract is a collection of code, functions and data. Contract resides on a specific address on Ethereum blockchain

uint storedData Unsigned Integer that represents some data.

    function set(uint x) public {
        storedData = x;
    }

    function get() public view returns (uint) {
        return storedData;
    }
}

Getters and setters. What's interesting the visibility of the function is declared after the list of arguments. The keyword view indicates that method get() won't modify the state of the contract.