Sometime we need to apply time base restrictions for special offer or ICO. Below, is the example for timebase restriction.
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
contract timeBaseRistriction{
uint creationTime = block.timestamp;
uint maxtime = creationTime + 1 minutes;
modifier timeLimit(uint _time){
if(block.timestamp < _time)
revert("Time restriction");
_;
}
//this method to able called after 2 minute
function call1() public payable timeLimit(maxtime){
}
//this method to able called after 3 minute
function call2()public payable timeLimit(maxtime + 2 minutes){
}
function getBalance()public view returns(uint){
return address(this).balance;
}
}