Skip to content

Instantly share code, notes, and snippets.

@dicethedev
Created August 2, 2022 04:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dicethedev/891f04df0a56cf154804386eb1d89a7e to your computer and use it in GitHub Desktop.
Save dicethedev/891f04df0a56cf154804386eb1d89a7e to your computer and use it in GitHub Desktop.
Increment and Decrement counter in solidity and adding stop time to get it
//SPDX-License-Identifier: MIT
pragma solidity 0.8.7;
contract Counter {
uint public count;
uint timestop = block.timestamp + 30 seconds;
//set block.stamp should not be more than 30 seconds
function add() public {
require(block.timestamp <= timestop, "your time is up");
count ++;
}
function dec() public {
require(block.timestamp <= timestop, "your time is up");
count --;
}
// returning count value from the state variable that is declared outside the function
function getCount() public view returns (uint) {
return count;
}
//this will return the timestamp of the function or operation
function TimeStamp() public view returns (uint e) {
e = timestop - block.timestamp;
return e;
}
//this will return how many seconds you used when incrementing or decremmenting the count
function timeReturn() public view returns (uint) {
return block.timestamp;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment