Last active
August 1, 2022 16:40
-
-
Save amarachiugwu/3b07198f611f0f36aca295b923b91714 to your computer and use it in GitHub Desktop.
increment and decrement a count in solidity
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.0; | |
| contract increamentDecreament { | |
| // counter | |
| uint count = 1; | |
| uint256 deadline = block.timestamp + 30 seconds; | |
| modifier timer () { | |
| require (block.timestamp < deadline, "deadline reached"); | |
| _; | |
| } | |
| // increament | |
| function Add() public timer { | |
| count++; | |
| } | |
| // decreament | |
| function subtract() public timer { | |
| count--; | |
| } | |
| // return count | |
| function getCount() public timer view returns(uint) { | |
| return count; | |
| } | |
| } |
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
| create a smart contract that | |
| increaments a count | |
| deceament a count | |
| display the value of counte | |
| but stops the increament and decreament operaton on count after 30 seconds of contranct deployment |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment