ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Solidity란 & 기본 개념
    Block-Chain/Solidity 2022. 12. 23. 17:38

    Solidity의 기본 개념에 대해 정리하였습니다.

     

     


    < Introduction >

    솔리디티(Solidity)란 스마트 컨트랙트(Smart Contract) 작성 및 구현에 사용되는 객체 지향 언어입니다.

    스마트 컨트랙트(Smart Contract)란 정해진 조건이 충족되었을 시 실행되는, 블록체인 안에 저장되어 있는 프로그램입니다.

     

    Remix: Ethereum IDE

    https://remix.ethereum.org/#optimize=false&runs=200&evmVersion=null&version=soljson-v0.8.7+commit.e28d00a7.js 

     

    Remix - Ethereum IDE

     

    remix.ethereum.org

    +. Truffle로도 이더리움 스마트 컨트랙트 배포, 컴파일, 관리 등이 가능

     

     


    < Solidity 기본 구조 >

    // SPDX-License-Identifier: GPL-30
    pragma solidity >= 0.7.0 < 0.9.0;
    
    contract Hello {
        string public hi = "Hello solidity";
    }

    1. SPDX 라이센트 명시 : 

     - 라이센스를 명시함으로써 스마트컨트랙에 대한 신뢰감 높임

     - 스마트 컨트랙 소스코드 저작권 관련 문제 해소

     

    2. Solidity 버전 명시

     

    3. Contract 작성

     

    4. 코드 마지막 마다 Semicolon ; 작성

     


    < Data Type >

    Solidity는 크게 Data TypeReference TypeMapping Type 3가지 타입이 있습니다.

    Data Type에는 4가지가 있습니다.
    : boolean, bytes, address, uint

     

    • boolean : true / false 2가지 값을 가짐.

    Ex) boolean 변수 정의 

    bool public b = false;
    
    // Solidity에도 연산자 존재 : !, ||, ==, &&
    bool public b1 = !false; // true
    bool public b2 = false || true; // true
    bool public b3 = false == true; // false
    bool public b4 = false && true; // false

     

    • bytes : 1~32 바이트까지 저장 가능

    Ex) bytes 변수 정의

    bytes4 public bt = 0x12345678;
    bytes public bt2 = 'STRING';

    : 숫자 1개가 4 bit, 즉 2개면 1 byte

     

    • address : 지갑 주소나 스마트컨트랙트 주소 등 주소값

    Ex) address 변수 정의

    address public addr = 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4;

     

    • int/uint : 정수값(uint는 unsigned integer 즉 부호가 없음: 음수가 없음)

    Ex) int/uint 변수 정의

    // int8 : -2^7 ~ 2^7-1
    int8 public it = 4;
    
    // uint8 : 0 ~ 2^7-1
    uint8 public uit = 132;

    +. uint == uint256 같은 의미임.

     

    < Solidity 연산자 >
    plus : +

    minus : -
    multiply : *

    divide : /
    not : !
    or : ||
    equal :==
    and :&&

     

     


    < Ether/GWei/wei, 그리고 Gas >

    1 ether는 10^9 GWei와 같고,
    1 GWei는 10^9 wei와 같습니다.

    Gas란 트랜잭션 발생 시 지불하는 비용

     

    - 1 Ether = 10^9 GWei = 10^18 wei

    - 0.000000000000000001 ether = 1^-18 = 1 wei

     

     

     

     

     

     

    'Block-Chain > Solidity' 카테고리의 다른 글

    조건문 & 반복문  (0) 2023.02.15
    Mapping & Array & struct(구조체)  (0) 2023.01.16
    상속 & 이벤트  (0) 2023.01.05
    Instance  (0) 2022.12.28
    Function  (0) 2022.12.26

    댓글

Designed by Tistory.