0

I have a problem regarding modifying block.timestamp. I would like to modify timestamp in my network and change block.timestamp to unix timestamp, but I got an error at modification:

TypeError: Expression has to be an lvalue.

block.timestamp = 1577836800;

Is any solution to go through this obstacle? Am I even able to modify block.timestamp in that way?

0

The error you are getting is that you cannot set a value to this variable, because it is not an editable variable.

Special Variables and Functions

There are special variables and functions which always exist in the global namespace and are mainly used to provide information about the blockchain.

block.timestamp itself is a protected keyword in solidity that has a specific value of the block timestamp for the block that ran this code. You cannot set that value.

Maybe you intend to set another variable to your value, and then have some check to see when these two values are equal?

Like:

uint checkblock = 1577836800;

if (checkblock <= block.timestamp) {
   //code here
}
  • I would like to set my request with a given period of time - both as a delay, after which my transaction will execute and an unix timestamp, when my transaction will execute. Although I got on well with delaying in seconds or even minutes my transaction, I would like to add logic to make my transaction is executing at given unix time, not waiting few years till transaction gets executed. – wmk Nov 2 '18 at 10:42
  • Unfortunately you cannot do what you are looking for. All solidity code execution happens as a result of an external transactions, and happens as soon as that transaction is mined. Additionally, valid transactions submitted to the network will get mined as soon as a miner includes it into the block, and has no way to "delay" per the submitter's instruction. What you might want is an external service to hold the transaction and not submit it until a specific time. Something like this (Though I have never used this myself). – Shawn Tabrizi Nov 2 '18 at 10:57
  • Ack, so I guess I just had to make some kind of schedule in my smart contract. Thanks for sharing your knowledge! – wmk Nov 2 '18 at 11:01
  • I should note though that the lowest granularity you can achieve on the blockchain is the time between blocks. Blocks are discrete, not continuous. – Shawn Tabrizi Nov 2 '18 at 11:03
0

No, you cannot modify it. It the time that block was sealed by the miner

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.