Global Variables

In Solidity, there are several global variables available that provide information about the blockchain and the contract itself. These include:

  1. block: Provides information about the current block being mined, such as its number, timestamp, and difficulty.

  2. msg: Provides information about the message that triggered the current function call, such as the sender's address, the amount of ether sent, and the data sent with the message.

  3. tx: Provides information about the current transaction, such as its hash, sender, and gas price.

  4. this: Refers to the current contract instance and allows accessing its properties and functions.

These global variables can be used to write smart contracts that interact with the blockchain and other contracts in various ways. For example, msg.sender can be used to verify that a transaction was sent from a specific address, and now can be used to add a time-based condition to a contract.

For all of the global variables visit:

Prior to version 0.5.0, Solidity allowed address members to be accessed by a contract instance, for example this.balance. This is now forbidden and an explicit conversion to address must be done: address(this).balance.

Last updated