본문 바로가기

study/BlockChain

값 타입

728x90

Boolean 형

타입
bool true/ false
bool x = false;

 

정수형

타입 추가설명 ex
int 8 bit~ 256 bit int == int256 int32 x = -27462;
uint 8 bit~ 256 bit uint ==uint256 uint256 x= 24557867;

 

주소형

타입 추가설명
address

20 byte 값

이더리움 계정 주소

두개의 멤버 소유: balance, transfer

address x= 0x123;

function send() public {
	if (x.balance <10) {
    	x.transfer(10);
    }
}

 

고정된 크기의 byte 배열

타입 추가설명
bytes 1 byte~ 32 byte byte ==bytes1
bytes32 x= "hello world";

솔리디티는 string에 최적화되어있지 않음.

32바이트를 초과하면 string쓰고 길지않으면 byte타입으로 쓰자.. 

가스비용이 바이트타입보다 더 나온다...

 

동적인 크기의 byte 배열

타입 추가설명
bytes/ string 무한 값 타입x
bytes[] names;

 

열거형

타입 추가설명
enum 이름{value,value2} 값을 정수형으로 리턴
enum Direction {Right, Left}
Direction direction;

function getDirection() public returns (uint) {
	return uint(direction);
}

function setDirection(uint newDirection) public {
	direction = Direction(newDirection);
}

 

728x90
반응형

'study > BlockChain' 카테고리의 다른 글

컨트랙 최적화  (10) 2019.10.12
가스란?  (4) 2019.10.12
함수 타입 제어자  (2) 2019.10.05
접근 제어자  (2) 2019.10.05
컨트랙의 구조  (3) 2019.10.05