Created
May 4, 2023 00:47
-
-
Save TehilaFavourite/9e34cf737de19cd472c1ee64b1d30607 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Global variables | |
contract GlobalVariablesDemo { | |
// Current block data | |
uint256 public currentBlockNumber; | |
uint256 public currentBlockTimestamp; | |
address public currentBlockMiner; | |
// Transaction data | |
address public transactionSender; | |
uint256 public transactionValue; | |
// Message data | |
address public messageSender; | |
bytes public messageData; | |
// Contract data | |
address public contractAddress; | |
uint256 public contractBalance; | |
constructor() payable { | |
// Get current block data | |
currentBlockNumber = block.number; | |
currentBlockTimestamp = block.timestamp; | |
currentBlockMiner = block.coinbase; | |
// Get transaction data | |
transactionSender = msg.sender; | |
transactionValue = msg.value; | |
// "msg.value" and "callvalue()" can only be used in payable constructors. Make the constructor "payable" to avoid error. | |
// Get message data | |
messageSender = tx.origin; | |
messageData = msg.data; | |
// Get contract data | |
contractAddress = address(this); | |
contractBalance = address(this).balance; | |
} | |
// Function to receive Ether | |
receive() external payable { | |
contractBalance = address(this).balance; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment