Verified contractPartialMIT
OnChainGM
Address0xc5c68144edac2e1872f744c2b07acc5a78f6e63e
- Balance
0 ETH
- Transactions
14,006
- Compiler
solc 0.8.28
- Same code
Only this contract
Details
- Compiler
- solc 0.8.28+commit.7893614a
- Language
- solidity
- Optimization
- Yes, 1,500,000 runs
- License
- MIT
- Match
- Partialcreation code: no, runtime code: yes
- Verified on Sourcify
- Created in block
- 21,958,868
- Creation transaction
- 0x6185cd910b…5e02b7924f
.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
contract OnChainGM {
// Immutable variables don't use storage slots
address public immutable feeRecipient;
uint256 public immutable GM_FEE;
uint256 public constant TIME_LIMIT = 24 hours;
// Mapping to store last GM timestamp for each user
mapping(address => uint256) public lastGMTimestamp;
// Event for tracking GMs
event OnChainGMEvent(address indexed sender);
constructor() {
feeRecipient = 0x7500A83DF2aF99B2755c47B6B321a8217d876a85;
GM_FEE = 50 ether;
}
// Gas optimized GM function with timestamp check
function onChainGM() external payable {
if (msg.value != GM_FEE) {
revert("Incorrect ETH fee");
}
// Check if 24 hours have passed since last GM
if (!(block.timestamp >= lastGMTimestamp[msg.sender] + TIME_LIMIT || lastGMTimestamp[msg.sender] == 0)) {
revert("Wait 24 hours");
}
// Update last GM timestamp
lastGMTimestamp[msg.sender] = block.timestamp;
// Transfer fee after all checks
(bool success,) = feeRecipient.call{value: msg.value}("");
if (!success) {
revert("Fee transfer failed");
}
emit OnChainGMEvent(msg.sender);
}
// View function to check remaining time
function timeUntilNextGM(address user) external view returns (uint256) {
if (lastGMTimestamp[user] == 0) return 0;
uint256 timePassed = block.timestamp - lastGMTimestamp[user];
if (timePassed >= TIME_LIMIT) return 0;
return TIME_LIMIT - timePassed;
}
}
Compiler settingsShow
{
"metadata": {
"bytecodeHash": "ipfs"
},
"libraries": {
".sol": {}
},
"optimizer": {
"runs": 1500000,
"enabled": true
}
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.