Solidity- 027TransactionAndMessageVariables

// SPDX-License-Identifier: MIT

pragma solidity >=0.7.0 <0.9.0;

contract TransactionAndMessageVariables {

    // Define events for logging different types of data

    event logstring(string);

    event loguint(uint);

    event logbytes(bytes);

    event logaddress(address);

    event logbyte4(bytes4);

    event logblock(bytes32);

    // Function to log global variables related to transactions and blocks

    function globalVariable() public payable {

        // Emit the miner's address (coinbase is the address where block rewards are given)

        emit logaddress(block.coinbase);

        // Emit the difficulty of the current block (a measure of how difficult it is to mine the block)

        emit loguint(block.difficulty);

        // Emit the block's gas limit (maximum amount of gas that can be spent on transactions in the block)

        emit loguint(block.gaslimit);

        // Emit the amount of gas left for the current transaction

        emit loguint(gasleft());

        // Emit the gas price set by the transaction

        emit loguint(tx.gasprice);

        // Emit the current block number

        emit loguint(block.number);

        // Emit the timestamp of the current block (in Unix time)

        emit loguint(block.timestamp);

        // Emit the data field from the transaction (if any)

        emit logbytes(msg.data);

        // Emit the first 4 bytes of the call data (function identifier)

        emit logbyte4(msg.sig);

        // Emit the amount of Ether (in Wei) sent with the message

        emit loguint(msg.value);

        // Emit the sender's address (address initiating the contract call)

        emit logaddress(msg.sender);

        // Emit the original sender's address (address that initiated the transaction)

        emit logaddress(tx.origin);

        // Emit the hash of the given block number (in this case, the current block number)

        emit logblock(blockhash(block.number));

    }

}

//Deploy:

Solidity- 027TransactionAndMessageVariables_第1张图片

你可能感兴趣的:(Solidity,区块链,智能合约,信任链,去中心化,分布式账本,共识算法)