Created
August 2, 2022 04:19
-
-
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
This file contains 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.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