Skip to content

Instantly share code, notes, and snippets.

@amarachiugwu
Last active August 1, 2022 16:40
Show Gist options
  • Select an option

  • Save amarachiugwu/3b07198f611f0f36aca295b923b91714 to your computer and use it in GitHub Desktop.

Select an option

Save amarachiugwu/3b07198f611f0f36aca295b923b91714 to your computer and use it in GitHub Desktop.
increment and decrement a count in solidity
// 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;
}
}
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