Let's say I have deployed a smart contract game that rewards the first user that writes to contract after a point in time T. Naturally, every player will try to be that winner, causing many requests to hit the network at once. If anyone could go into as much technical detail as possible, how does the Ethereum network determine who would be the winner of this game?


1 Answer 1


There are no actual race conditions in the Ethereum network. All transactions are executed after each other and in the end there is no parallelism. You can read a bit more here: how to deal with race condition and execution times of a contract? and What is the order of operations to verify a transaction?

So basically it's the miners who decide on the actual order of the transactions in a block. Typically miners prefer transactions with a high gas price because they get to keep the gas in the blocks themselves. But there is nothing enforcing any particular order: a miner can include whatever transactions he wants in a block and it's as valid block as any other (if he manages to solve the PoW task of finding the right nonce value).

If you are indeed checking for transactions which occur after a certain time and not after a certain block then to have the biggest chance of winning a participant should basically issue his transaction at exactly the right time (probably a bit before the given time because transaction propagation takes time) with a high gas price. If the price is right, it will most likely be included in the next block and possibly even as the first transaction. But as I said there is no way to be sure of this - miners decide on the eventual order of transactions and which to include in a block.

  • Thank you so much for the answer! You're very clear that it is all about the gas price that the user is willing to pay that has the best chance of winning. However, here's my followup question: assuming that the users are writing to the same smart contract across different nodes, how would the nodes come to consensus over who was the winner?
    – brianSan
    Apr 6, 2019 at 4:36
  • 1
    Consensus is a bit separate different topic. Basically the nodes don't make decisions but the network has the ability to reach consensus as a whole. Eventually some block is determined to be the "right" block and therefore order of transactions is decided. Apr 6, 2019 at 6:42

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