1

This question already has an answer here:

Can someone tell me where smart contracts are actually executed? Is it on the miners or the nodes? Is it run in all miners/nodes, or just one? Also if I declare a variable where is that state persisted? On the blockchain or other storage?

marked as duplicate by lungj, Richard Horrocks, Jesse Busman, Ismael, Rob Hitchens Dec 25 '17 at 22:23

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

5

Every full node (those participating in mining and those not) runs the smart contract code involved in every transaction.

Your second question is answered here: Where is the state data stored?. Essentially, because that state is computed from the transactions that make up the blockchain, that storage doesn't need to itself be part of the actual blockchain structure. But in practice, it doesn't make much of a difference. (Nodes store it, just like they store the blockchain.)

  • Thanks, does running on all nodes cause problems with the order in which transactions are received by the contract? If one transaction request adds 10 to a value and a second transaction squares a value, the order these are received will have different outcomes. Or is this type of operation not allowed? – Slicc Dec 23 '17 at 19:23
  • 1
    The order of the transactions is determined by the miner who mined the block. All the other nodes are just validating that the block broadcast by the miner is valid, so they process the included transactions in the order determined by the miner. (Additionally, multiple transactions originating from the same address do have a defined order, so they can never appear out of order.) – smarx Dec 24 '17 at 1:51

Not the answer you're looking for? Browse other questions tagged or ask your own question.