2

I'm facing a doubt while developing an Smart Contract. I was getting current date from block.timestamp several times inside a function. Could this value change during an Smart Contract execution? Or the Smart Contracts are executed in the same block, so block.timestamp, block.number... have always the same value, during the execution?

Obviously, if not, solution is simple. Getting block.timestamp in a variable value on init, and use the variable value during the execution.

uint foo = block.timestamp;

1 Answer 1

4

Values such as block.timestamp and block.number are, as expected, based on the block. So one block always has the same data.

A block typically contains multiple transactions. So if you send two transactions to your smart contract, they may both end up in the same block and therefore both of them will have the same values in the aforementioned variables. But a transaction in another block will have different values.

One execution is always inside one transaction, so the values are always the same inside the same execution and transaction.

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.