Solidity 문법 - (2) 솔리디티 타입

2023. 5. 29. 04:44BlockChain/Solidity 깨부수기 ( 유투브 강의 )

목차
1. 솔리디티 타입
2. 타입 예제 코드

 

1. 솔리디티 타입

 

 

Solidity에서 쓰이는 타입들에 대해서 알아보자.

 

솔리디티에서는 크게 세 가지의 타입이 있다.

 

 

data type

 

  • boolean - 참, 거짓을 나타낸다.

 

  • bytes - 바이트를 지정해준다. 예를 들어 4bytes면 0x12345678 로 나타낼 수 있다.

 

  • address - 솔리디티에서 볼 수 있는 특수 타입으로 CA나 EOA를 받을 수 있다.

 

  • int - 숫자 타입이며, 음수부터 양수까지 나타낼 수 있다.
    • int[number]는 -2^[number - 1] ~ 2^[number - 1] 까지의 범위를 나타낸다.

 

  • uint - 숫자 타입이며, 양수만을 나타낼 수 있다.
    • uint[number]는 0 ~ 2^[number] - 1 까지의 범위를 나타낸다.

 

아래의 타입은 있다는 것만 알고 추후에 자세히 알아보자.

 

 

reference type

 

  • string

 

  • Arrays

 

  • struct

 

mapping type

 

  • mapping

 

 

2. 타입 예제 코드

 

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract Data_type {
    bool public a1 = false; // false
    bool public a2 = !false; // true
    bool public a3 = false == true; // false
    bool public a4 = false && true; // false
    bool public a5 = false || true; // true

    bytes4 public b1 = 0x12345678; // 0x12345678
    bytes public b2 = "STRING"; // 0x535452494e47

    address public c1 = 0x513467D8d19eB33E6A5bB570C96E46A56370C978; // 0x513467D8d19eB33E6A5bB570C96E46A56370C978

    int8 public d1 = 1; // BN { negative: 0, words: [ 1, <1 empty item> ], length: 1, red: null }
    uint8 public d2 = 255; // BN { negative: 0, words: [ 255, <1 empty item> ], length: 1, red: null }
}

 

 

 

출처: 솔리디티 깨부수기
https://www.youtube.com/watch?v=e8KUldS69fU&list=PLJQKWHLhBrxI43w0DU4uQrhWv4Pm1OFlx&index=2