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:

  • 10
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值