본문 바로가기
BlockChain/solidity

[Solidity] 전역변수 알아보기

by BEJM 2022. 5. 21.

전역 변수

일단적으로 전역 변수는 어떤 변수 영역 내에서도 접근할 수 있는 변수를 의미합니다. Solidity에서 전역변수는 블록체인 안에 있는 변수로, 블록체인 및 트랜잭션에 대한 속성을 가져올 수 있습니다.

 

block

블록에 대한 정보를 가지고 있습니다.

block.blockhash(uint blockNumber) returns (bytes32) 주어진 블록의 해시
block.coinbase(address) 현재 블록 채굴자의 주소
block.difficulty(uint) 현재 블록 난이도
block.gaslimit(uint) 현재 블록 gaslimit
block.number(uint) 현재 블록 번호
block.timestamp(uint) || now(uint) unix epoch 이후의 현재 블록 타임스탬프/별칭으로 now

 

msg

컨트랙트를 시작한 트랜잭션 콜이나 메시지 콜에 대한 정보를 가지고 있습니다.

msg.gas  =>  gasleft() returns (uint256) 잔여 가스/0.4.21버전 에서 제거되고, gasleft()로 대체됨
msg.data(bytes) 완전한 calldata
msg.sender(address) 메세지 발신자
msg.sig(bytes4) calldata의 첫 4byte(함수 식별자)
msg.value(uint) 메세지와 함께 전송된 wei의 수

 

tx

트랜잭션 데이터를 가지고 있습니다.

tx.gasprice(uint) 트랜잭션의 가스 가격
tx.origin(adress) 트랜잭션 발신자

댓글