Created
August 1, 2022 17:56
-
-
Save casweeney/7f6dea0fe2ca30724894f84c43ac98ed to your computer and use it in GitHub Desktop.
Count implementation by Koko codes
This file contains hidden or 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
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8; | |
// create a timer for increement and decreement but they should only work after 30secs | |
contract counter { | |
uint256 count; | |
uint256 lastRun; | |
function add() external { | |
require(block.timestamp - lastRun > 30 seconds, 'Need to wait 30 seconds, be calming down'); | |
// TODO perform the action | |
lastRun = block.timestamp; | |
count++; | |
} | |
function dec() external { | |
require(block.timestamp - lastRun > 30 seconds, 'Need to wait 30 seconds, be calming down'); | |
// TODO perform the action | |
lastRun = block.timestamp; | |
count--; | |
} | |
function getlastRun() public view returns (uint256){ | |
return count; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment