Skip to content

Latest commit

 

History

History
39 lines (30 loc) · 1.23 KB

06.3-solidity.md

File metadata and controls

39 lines (30 loc) · 1.23 KB

Solidity

Solidity is a statically typed, contract programming language that has similarities to JavaScript and C. It is designed for writing smart contracts that run on the Ethereum Virtual Machine (EVM).

Smart Contracts

  • Smart contracts are self-executing contracts with the terms of the agreement between buyer and seller being directly written into lines of code;
  • Flexible;
  • Transparent -> trusted;
  • DeFi - decentralized finance.

Example

pragma solidity ^0.5.2;
contract Coin {
    address public minter;
    mapping (address => uint) public balances;

    constructor() public {
        minter = msg.sender;
    }

    function mint(address receiver, uint amount) public {
        require(msg.sender == minter);
        require(amount < 1e60);
        balances[receiver] += amount;
    }
}
  • pragma - version of the Solidity compiler this code should use;
    • ^ - compatible with the specified version and all future versions;
  • contract - keyword to declare a new contract - like a class;
  • address - type of Ethereum addresses;
  • mapping - a key-value store for storing and looking up data;
  • constructor - function that runs once when the contract is created;

to continue