0

I am creating a smart contract that will allow actions to be taken during a specific time period.

Ideally, I would like to let users know in advance the start block/end block that the contract will be available.

If I had a date in mind (say September 30 at 00:00:00 UTC), is it possible for me to calculate which block will likely be mined at that time? It doesn't have to be exact.

0

As per My experience, If you know the exact start and end date with time, for an action to be carried out. It easy to implement. For example in solidity,

uint256 starttime = 1505217600    // 09/12/2017 @ 12:00pm (UTC)
uint256 endtime = 1505304000     // 09/13/2017 @ 12:00pm (UTC)

// This function will execute only between start time and end time
// now return current time of blockchain in unix timestamp
function _d0 {
require ( now >= startime && now <= endtime );
/*
Write your action 
*/
}

You can convert time to unix timestamp here

1

Perhaps you could use solidity's time units to achieve what you want:

Suffixes like seconds, minutes, hours, days, weeks and years after literal numbers can be used to convert between units of time where seconds are the base unit and units are considered naively in the following way:

    1 == 1 seconds
    1 minutes == 60 seconds
    1 hours == 60 minutes
    1 days == 24 hours
    1 weeks == 7 days
    1 years == 365 days

Take care if you perform calendar calculations using these units, because not every year equals 365 days and not even every day has 24 hours because of leap seconds. Due to the fact that leap seconds cannot be predicted, an exact calendar library has to be updated by an external oracle.

Or you could use block.timestamp in block properties and test for nth block on Sept 30th..

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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