18

In a function, does block.timestamp record the time the transaction was processed, or the time the block.timestamp computational step was processed?

Is block.timestamp the time the transaction is processed, or would time and time2 differ ?

function doSomething() {

uint time = block.timestamp

// ... a few 400000 gas of other things ... //

uint time2 = block.timestamp

}
Badr Bellaj
  • 18,780
  • 4
  • 58
  • 75
iamlearning
  • 181
  • 1
  • 1
  • 3

3 Answers3

14

As per the documentation you will find

timestamp of the current block in seconds since the epoch

so you have a single timestamp (when it is created) per block therefore time1=time2

read more about timestamp at Is the block.timestamp value in Solidity seconds or milliseconds?

Badr Bellaj
  • 18,780
  • 4
  • 58
  • 75
7

In reference to your comment about transaction timestamps, the timestamps of all transactions in a block are the same.

There can be many transactions in a block, all have the same timestamp, and all are the same timestamp as the block's.

Thomas Jay Rush
  • 9,943
  • 4
  • 31
  • 72
5

block.timestamp is the value what miner decides to publish there when he or she finds a block.

It is subject to some interpretation and can be skewed, though only for a while. In practice this is not a real problem and risks of using block number are often higher.

How would a miner cope with a huge block time?

How does Ethereum avoid inaccurate timestamps in blocks?

https://ethereum.stackexchange.com/a/428/620

Mikko Ohtamaa
  • 22,269
  • 6
  • 62
  • 127