3

I am using "now" to save the block timestamp details. But there is a warning to avoid its usage. If we need to avoid it what is the best alternative to it.

enter image description here

2
  • 2
    I think the linter is just getting a bit overzealous. As long as you don't need precise time, now is fine. Jul 8, 2019 at 3:23
  • @TjadenHess: This comment should be the accepted answer! Jul 8, 2019 at 9:08

2 Answers 2

6

The use of block.timestamp (which is what now is an alias of) is often discouraged because it is somewhat manipulable by miners. This is only an issue if you need the time to be precise to within ~90 seconds, if you care about longer time scales where precise timing is unimportant then now is perfectly fine.

3

The community likes to use exact things like "block numbers" which cannot be tampered with by the miners.

The now / block.timestamp can be manipulated by the miner to a certain degree as it relies on the machine's time that actually found the block, and that's why the linter is telling you not to use it.

If you're not using that time for really important things like "awarding value to winners" you're fine using it.

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.