0

I'm trying to understand what is `block.timestamp' I have the following code in my contract:

require(block.timestamp >= publicSalesStartTime, "Not started yet");

what the block.timestamp returns? The simple answer will be "the current block's timestamp" But, is it the block that has already been mined or a new block that transactions are currently being collected and will be mined soon?

2 Answers 2

0

Long answer: It is the time in seconds that the block was mined. Note that this is not the time when the code was executed in the EVM. What happens? The miner chooses some transactions and mines the block with those transactions. It is the miner who chooses the moment when the block was mined. It doesn't need to execute smart contract code to mine the block, just validate that such transactions are well signed and valid.

Short answer: It is the time of the block that the transaction is 'inside'.

0

It is the latter. It is the timestamp of the block that this transaction will be included in. Note that in a lot of use cases, relying on the timestamp of a block is not totally safe. This is because the block timestamp can be manipulated by miners within some margin, so I would take caution in relying on 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.