August 2019
Intermediate to advanced
486 pages
13h 52m
English
The auto deprecate pattern allows time-based access to certain function calls. In Solidity, using the block.timestamp and now calls, you can get the time of the block when it is mined. Using this time, you can allow or restrict certain function calls in Solidity. There are also some globally available time units present in the Solidity language that you can use. These time units are seconds, minutes, hours, days, weeks, and years. You can use these time units to calculate the Unix epoch time in the past or in the future.
In the following code, the contribution() function should only be called in a specified duration of time:
contract AutoDeprecate { uint startTime; uint endTime; modifier whenOpen() { require(now > startTime ...