I want a function to only be able to be called after a certain specific period of time has passed from the contract's inception. Generally, I was using block.number for that. As in:

require(block.number >= 8000000);

However, if I want to use block.timestamp, could I do as below:

contract Time is owned {

    uint today;

    constructor() public {
       today = block.timestamp;

Declare 'today', and then set a requirement:

require (block.timestamp >= today + 365 days);

Will that work in preventing that the function gets called before 365 days pass from the publishing of the contract?

1 Answer 1


You're totally right! The way you do has no problem. You can make a test with small time like require (block.timestamp >= today + 60 seconds);

  • 3
    But be aware that the time should not be too small in practice. Miners can vary the timestamp of the block by up to 30 seconds.
    – schemar
    Sep 8, 2018 at 22:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.