3

In Ethereum as I know that every full node executes the transaction of the contract, hence if there is a code as follows:

f() { 
   string x; 
   if(time()<12) 
       x=AM 
   else 
      x=PM
} 

So if a transaction arrived to a node before 12 and to another node after 12 does that mean that the valuse of x is diffrent depending on the node.

6

Ethereum, like all blockchains, are fully deterministic and all smart contract executions give the same results on all nodes.

In this case time() or now (alias for block.timestamp) as it is called in Solidity is the timestamp of the block when it was mined.

This is set by the miner. By the network rules it can vary +-3 minutes of the UTC time the other network nodes have, or nodes will reject the new block.

So when the smart contract refers to the now, the time is actually the timestamp when the block where the transaction was included was mined.

| improve this answer | |
  • Should we also consider blockhash(n) since block hash can be influenced by miners to some degree. – alper Mar 20 at 1:02

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.