Solidity - Variables - GeeksforGeeks

GLOBAL VARIABLES


Variable Return value
blockhash(uint blockNumber) returns (bytes32) Hash of a given block, works for only 256 most recent transactions excluding current blocks
block.coinbase (address payable) Address of current blocks miner
block. difficulty (uint) The difficulty of the current block
block. gaslimit (uint) Gaslimit of the current block
block. number (uint) Block number of the current block
block. timestamp (uint) The timestamp of the current block as seconds since Unix epoch
gasleft() returns (uint256) Amount of gas left
msg. data (bytes calldata) Complete call data of block
msg. sender (address payable) The sender of message i.e. current caller
msg.sig (bytes4) First four bytes of call data i.e. function identifier
msg. value (uint) Amount of Wei sent with a message
now (uint) The timestamp of the current block
gasleft() returns (uint256) Amount of gas left
tx.gasprice (uint) Price of gas for the transaction
tx.origin (address payable) Transaction sender

Example: In the below example, the contact Test uses the msg.sender variable to access the address of the person deploying the contract.

// Solidity program to 
// show Global variables 
pragma solidity ^0.5.0; 

// Creating a contract 
contract Test { 
	
// Defining a variable 
address public admin; 
	
// Creating a constructor to 
// use Global variable 
constructor() public {	 
	admin = msg.sender; 
} 
}

Output: