I have a contract with a function that increments a value, but contains a check in a require statement to verify that the incremented value is not over a specified threshold... here's some pseudo-code of what I am referring to:

contract mycontract{

uint threshold = 5;

uint value;

function myFunction(){
   value = value + 1
   require(value <= threshold)
   //do something 

What Im wondering is if there are multiple calls to myFunction() within the same block, how will this act? Im not sure how to create a bundle of transactions all within the same block to test it. If value is equal to 4 in the above example, and there are 3 calls to myFunction() in the same block, will all 3 function calls have reference to the same Value=4 or will the first call execute, increment value to 5, finish the function execution and then the second call will have Value=5 and fail the require check and third call Value=5 and fail as well?

  • After doing some more research I believe the transactions are processed in sequence and not in parallel so only the first of the 3 transactions would not revert in my above example, please correct me if I am wrong
    – 0x Mesaj
    Apr 21 at 18:32

You're right that transactions are processed in sequence. For transactions coming from the same address, these are ordered by their nonce and must be mined in order. Transactions from different accounts get ordered by the miners. They are not required to include anything in particular, which means that there is no correct order. They're incentivized to fill the blocks with as many transactions as possible, for the highest gas price. They can however re-order any transactions how they please (e.g in order to front-run certain transactions).

Also check out: What is the default ordering of transactions during mining?

Hope it helps.

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.