# Order of transactions in the same block

I am writing a Medium blog post about front-running and can't seem to find information about the order of the transactions in the same block. I have executed two trades, one with the lower fee, call it A: https://etherscan.io/tx/0x7332ec032bcd421e8137a623c542f38448bd7860b4b310acf4aef940dae85778, and one with the higher gasPrice and the same amount of gas, B: https://etherscan.io/tx/0x422d289768ce4fd6a7acf15dad9326ac80aaf0dcda696c306da69d5e83bfeb9b. They were both included in the same block: https://etherscan.io/block/9494989. Which transaction occurred first, A or B?

And in general, how does one retrieve the order of transactions in the same block?

• Wow, I had the same question yesterday! Commented Feb 18, 2020 at 5:59

Each transactions includes a transaction nonce - an incremental number. Miners include transactions in a block so that they order by nonce and transaction price (exact implementations vary). But they have to choose some order: all transactions are always executed one after the other, no parallelism. Here's some more info about the ordering: What is the default ordering of transactions during mining, in e.g. geth?

You can see the order (index) of the transactions in the block in Etherscan, for example your transaction https://etherscan.io/tx/0x7332ec032bcd421e8137a623c542f38448bd7860b4b310acf4aef940dae85778 , press "Click to see more" and check "Position" next to "Nonce". Each transactions has a unique position (index) inside a block. So "B" occurred after "A".

Miners have latitude about the order of the transactions in a block. There is flexibility. They can also choose which transactions to include from the transaction pool.

They are incentivized to pack as much as possible into a block, at the highest possible gas price. Each block has a block gas limit, a network property voted on by the miners. The transaction has a gas price, the price in ether the sender is willing to pay for execution. So, the incentives make it something like a game of Tetris ... pack in the most processing that will fit, with the highest reward, for the maximum possible transaction fees.

Note that they are not required to include anything in particular and there is no correct order. Indeed, the mining function is to establish a canonical order.

There is another constraint.

Each sending account as an account nonce that numbers the transactions. Transactions that originate from a given account must be mined in nonce order. This prevents replay attacks and also ensures that senders won't be surprised by the ordering of confirmed transactions.

Hope it helps.

• ah this is great! this means I cannot front-run myself. thank you
– nz_
Commented Feb 16, 2020 at 19:42
• would it qualify actually that a transaction originates from the same account if: I send one transaction from address A, and the second one that aims to front-run this transaction from a smart-contract B, that was created by A?
– nz_
Commented Feb 16, 2020 at 19:47
• "contract B, that was created by A" - created by A has the deterministic transaction ordering relative to "I send one transaction from address A". Commented Feb 16, 2020 at 20:51
• Have a look at pattern 3 in the original question over here for some more insights into the implications of deterministic ordering (by account). ethereum.stackexchange.com/questions/39790/… Commented Feb 16, 2020 at 20:53