I'm a ethereum beginner. I can't understand some of its concept.

for example, a contract should be executed by everyone on the network as a way to verify a block.

what about synchronization among all executions of the same program?

suppose I write a program to transfer $10 from my account to a friends as a penalty if I lost his book.

in this case, I only want one $10 transferred. but if my contract will be executed multiple times, then how to prevent multiple transfer?

2 Answers 2


You are mixing 2 layers of abstraction:

  • the distributed ledger, on which multiple machines do things many times to reach a consensus
  • the Ethereum Virtual Machine (EVM), which is an expression of the consensus, and which behaves like a single process computer.

So since your program computes in the EVM, it is unaware of the distributed ledger and the many machines involved.

  • behaves like a single process computer, but it will be executed many times, correct? if I have a http api that allows me to transfer money, and I write it into a contract, the contract will be executed many times, right? the api will be called many times?
    – Bill Yan
    Sep 4, 2016 at 21:03
  • Contracts can't directly call http apis. You could make an external service to watch the blockchain and call the API when the contract signalled that it should, but it may need to wait enough blocks to be confident that the state of the blockchain implying that it should make the call wasn't going to get orphaned. Sep 4, 2016 at 21:38

It is easier and in some ways more correct to think of your program as being executed exactly once, by the miner. When a miner mines a block, he collects all of the transactions that have occurred, puts them into a canonical order, and then executes each exactly once. After he is done running all of the code, he looks at the new state of the blockchain, and then takes the hash of that state, and puts that into the block.

This state is now the canonical state of the blockchain. As the block is propagated through the network, each node verifies that the computations in the block were all correct, and lead to this final state. They don't change the state. The only one who can change the state of the blockchain (including account balances) is the miner. Everyone else simply verifies that the miner didn't cheat, but they have no power to transfer funds or make any other changes.

  • I roughly understand the process, but still I can't understand how to write the above program correctly on ethereum. suppose a bank provides a rest api to allow me to transfer money. this program, if written as a contract, will be called many times, right?
    – Bill Yan
    Sep 4, 2016 at 21:01

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.