0

I am trying to store the timestamp in the blockchain using block.timestamp or now. But that keeps throwing warning as

Use of "block.timestamp": "block.timestamp" can be influenced by miners to a certain degree. That means that a miner can "choose" the block.timestamp, to a certain degree, to change the outcome of a transaction in the mined block.

What is the proper way to store timestamps? Is it good practice?

0

There is no other way to get the current timestamp. now is an alias for block.timestamp and yes, it can be influenced by miners (a bit). But that is the best there is.

Most of the time there is no reason for the miners to influence the timestamp. In some rare cases, when the possible reward is big enough, they might be incentivized to influence it. Such case might be some time-based gamble/lottery when the miner has their own transaction to be mined which needs a specific timestamp to have better chances of winning.

In some cases using block.number is a more secure alternative as it can't be influenced by miners. It can be used in a similar way as the timestamp as blocks happen at fairly regular intervals. Some more info here for example https://ethereum.stackexchange.com/a/10942/31933

| improve this answer | |
  • Thanks for your time and clarification. – NinjaMAN Jul 28 at 4:13

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.