Skip to content

Instantly share code, notes, and snippets.

@casweeney
Created August 1, 2022 17:56
Show Gist options
  • Save casweeney/7f6dea0fe2ca30724894f84c43ac98ed to your computer and use it in GitHub Desktop.
Save casweeney/7f6dea0fe2ca30724894f84c43ac98ed to your computer and use it in GitHub Desktop.
Count implementation by Koko codes
// 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