Block and transaction global variables
Solidity provides access to a few global variables that are not declared within contracts but are accessible from code within contracts. Contracts cannot access a ledger directly. A ledger is maintained by miners only; however, Solidity provides some information about the current transaction and blocks to the contracts so that they can utilize them. Solidity provides both block- and transaction-related variables.
The following code illustrates examples of using global transaction, block, and message variables:
// SPDX-License-Identifier: MIT pragma solidity >=0.7.0 <0.9.0; contract TransactionAndMessageVariables { event logstring(string); event loguint(uint); event logbytes(bytes); event logaddress(address); event logbyte4(bytes4); event logblock(bytes32); ...