<p>The Bitcoin protocol requires transactions to appear in <strong>topological order</strong> in the blockchain. Given two transactions A and B where B spends an output of A: </p>

<ul>
<li>Both A and B may be included in the same block.</li>
<li>A must precede B in the transaction list.</li>
</ul>

<p>Colloquially, a miner will never include a transaction in a block template until the transaction's requirements are met. Since B spends an output of A, B is not valid until A has created said output. To satisfy this dependency, B can only be included after A was included.</p>

<p>Also see: <a href="https://bitcoin.stackexchange.com/q/1726/5406">Can multiple transactions transferring the same bitcoin be done in one block?</a></p>

CC BY-SA 3.0
2014-08-08T22:41:46.163Z
I cannot understand this answer it seems to contradict itself.  It says 1) all transactions in a block happen at the same time, 2) A & B can be in same block but they will stand in chronological order.  2) means that 1) is not true, 2) means that transactions in a block are considered to happen in the order they are listed, not at the same time.  Fix!?!?
mwengler
CC BY-SA 3.0
2014-08-08T23:03:04.817Z
They don't have to be in different blocks, i.e. they will all be timestamped at the same time. It doesn't even matter if a miner receives knowledge of B first. However, if a miner were trying to first determine the validity of B, he would find it invalid, as he doesn't know about the transaction output created by A yet. Thus, even though the transactions can happen at the in the same block, the protocol enforces that the transactions will be written out in the block in the correct order.
Murch
CC BY-SA 4.0
2019-10-11T07:45:43.603Z
I am curious about unrelated transactions - how are they ordered? Surely a timestamp is insufficient? If it is a UUID, how is it ordered?
Angad
CC BY-SA 4.0
2019-10-11T14:52:21.830Z
They don't need to be in a specific order, but some miners seem to keep them in the same order they selected them into the block, i.e. ordered by the transactions' fee rates paid.
Murch
CC BY-SA 4.0
2014-03-05T08:02:36.460Z
2019-07-17T05:45:20.517Z
2019-07-17T05:45:20.517Z
Murch
<p>Does the Bitcoin protocol guarantee that within a valid block, if transaction B spends the outputs of transaction A, A will always precede B?</p>

<p>Or is it possible to have B before A?</p>

<blockchain><protocol>
Order of transactions within a block
Flavien
# Order of transactions within a block

(Asked by: username_0 on 2014-03-04)

Does the Bitcoin protocol guarantee that within a valid block, if transaction B spends the outputs of transaction A, A will always precede B?

Or is it possible to have B before A?

**Tags:** blockchain, protocol


---

## 1 answers

### Answer by username_1 on 2014-03-05. Score: 7 | Accepted answer

The Bitcoin protocol requires transactions to appear in **topological order** in the blockchain. Given two transactions A and B where B spends an output of A:

* Both A and B may be included in the same block.
* A must precede B in the transaction list.

Colloquially, a miner will never include a transaction in a block template until the transaction's requirements are met. Since B spends an output of A, B is not valid until A has created said output. To satisfy this dependency, B can only be included after A was included.

Also see: [Can multiple transactions transferring the same bitcoin be done in one block?](https://bitcoin.stackexchange.com/q/1726/5406)

> **Comments:**
> **username_2**: I cannot understand this answer it seems to contradict itself.  It says 1) all transactions in a block happen at the same time, 2) A & B can be in same block but they will stand in chronological order.  2) means that 1) is not true, 2) means that transactions in a block are considered to happen in the order they are listed, not at the same time.  Fix!?!?  
> **username_1**: They don't have to be in different blocks, i.e. they will all be timestamped at the same time. It doesn't even matter if a miner receives knowledge of B first. However, if a miner were trying to first determine the validity of B, he would find it invalid, as he doesn't know about the transaction output created by A yet. Thus, even though the transactions can happen at the in the same block, the protocol enforces that the transactions will be written out in the block in the correct order.  
> **username_3**: I am curious about unrelated transactions - how are they ordered? Surely a timestamp is insufficient? If it is a UUID, how is it ordered?  
> **username_1**: They don't need to be in a specific order, but some miners seem to keep them in the same order they selected them into the block, i.e. ordered by the transactions' fee rates paid.  

---

