1

I read somewhere that the 'state' is only updated at the end of each block. I've also read that each block contains a specific sequence of transactions, and thus implicitly 'updates' the state within a block. This might be semantics, but I just want to be certain about how state variables are updated: will a transaction that alters the state do so before the next transaction, regardless of whether it is in the same block?

To be clear: assume a contract variable Book is 10 ETH, so that users can take bets against this 10 ETH. Each time a transaction bets an amount X, Book is decreased by X: Book = Book - X. Bets are restricted so that Book>=0 at all times: require(Book - X >= 0) at the top of the betting function. If Bob bets 6 ETH, and Alice bets 6 ETH, this would obviously be counter to my requirement. However, if their transactions are in the same block, would the second transaction be rejected?

1

will a transaction that alters the state do so before the next transaction, regardless of whether it is in the same block?

Yes

if their transactions are in the same block, would the second transaction be rejected?

Yes

An important point is that neither Alice or Bob knows who is first: the miner decides which transaction is first.

See also What is the default ordering of transactions during mining?

| improve this answer | |

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.