1

Suppose I am running a gallery and ask participants to submit there paintings before a specific date. After passing that date participant should not be able to submit their entry. How can I implement such functionality?

3

There are two ways to do this:

1) Limit the deadline by the block number.

require(block.number < 7169670); // Where 7169670 is a block number.

2) Limit the deadline by the current timestamp.

require(now < 1549219795);  // Where 1549219795 is the current unix timestamp.

There are advantages for both. It is not recommended to use block.number for checks that are in a long time, as there is variance in timing of blocks and other factors such as the ice age.

now is preferred, as it is generally more accurate. With each mined block, miners include a timestamp of the current time. There are rules which limit their ability to manipulate this time (for example, it cannot be prior to the previous block's timestamp, nor can it be too much longer than it).

  • Why to use block.number is not recommended to use for checks in a long time? @shane – alper Oct 4 at 9:50
  • It was recommended to not use block.number back when the difficulty bomb existed. There were a number of contracts (usually ICOs), that used block.number and expected to start their ICO at a certain time. When the difficulty bomb happened, these start times got pushed back because of the longer block times. Thus, the reason to not use block.nunber is because the variance in block times in the short term (<infinity) is too large to accurately predict. – shane Oct 4 at 14:46
  • How about if it is network is proof-of-authorithy network and block time is fixed seconds such as 15 seconds? – alper Oct 4 at 15:19
  • I would say that is fine. Additionally, it should be fine for certain situations where precise timing isn't necessary. – shane Oct 4 at 15:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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