Skip to content

Instantly share code, notes, and snippets.

@TehilaFavourite
Created May 4, 2023 00:47
Show Gist options
  • Save TehilaFavourite/9e34cf737de19cd472c1ee64b1d30607 to your computer and use it in GitHub Desktop.
Save TehilaFavourite/9e34cf737de19cd472c1ee64b1d30607 to your computer and use it in GitHub Desktop.
// 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