TransWikia.com

What is the proper way to store timestamp in blockchain?

Ethereum Asked by NinjaMAN on December 5, 2021

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?

One Answer

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

Answered by Lauri Peltonen on December 5, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP