<blockquote>
<p>I want to get the mempool data ordered by sat/vbyte to understand which transaction will be confirmed.</p>
</blockquote>
<p>These two questions are not identical.</p>
<p>While of course mining prefers higher fees over lower fees, there are some reasons why the mining order is not exactly high to low fee:</p>
<ul>
<li>Dependencies: when a transaction A in the mempool spends an output of transaction B which is also in the mempool, then B must go into the block before A can. In practice, Bitcoin Core does take such dependencies into account to some extent: if A has a higher feerate than B, then the combination of A and B are treated as a single package, so that B &quot;pays for&quot; A, possibly bumping up A's mining priority.</li>
<li>Tail effects: near the &quot;end&quot; of a block, it's possible that the highest feerate transaction is too large to fit in the block. In that case the problem of block template building becomes a bin-packing problem, and may include whatever fits.</li>
</ul>
<p>To answer your question:</p>
<ul>
<li><p>If you want the mempool transactions sorted by fee/vbyte, use <code>getrawmempool</code>, and sort the result yourself by feerate. You could do this using <code>jq</code> for example:</p>
<pre><code>bitcoin-cli getrawmempool true | jq '[to_entries[] | .value] | sort_by(.fees.modified / .vsize)'
</code></pre>
</li>
<li><p>If you want the (order in which) transactions will end up in a block, use <code>getblocktemplate</code> (which is the RPC that mining pools use to get information of block transactions from Bitcoin Core):</p>
<pre><code>bitcoin-cli getblocktemplate '{&quot;rules&quot;:[&quot;segwit&quot;]}
</code></pre>
</li>
</ul>

CC BY-SA 4.0
2023-06-12T12:59:59.053Z
bitcoin-cli getrawmempool true | jq '[to_entries[] | .value] | sort_by(.fees.modified / .vsize)'
this method works but I also need to find the transaction hex but that data is not embeded in this query response  how can I also get the hex of each transaction
Gencehan ARPAÇAY
CC BY-SA 4.0
2023-06-12T13:14:18.147Z
Try using `bitcoin-cli getrawmempool true | jq -r '[to_entries[] | .value + {"txid":.key}] | sort_by(.fees.modified / .vsize) | .[] | .txid'`.
Pieter Wuille
CC BY-SA 4.0
2023-06-12T14:05:14.947Z
Due to child pay for parent effective fee rates could be smaller but due to higher sat/vbyte these txs are ordered and therefore a transaction which wont be confirmed is being listed in the tx array how can I prevent this
Gencehan ARPAÇAY
CC BY-SA 4.0
2023-06-12T14:44:45.300Z
@GencehanARPAÇAY As I said, if you want the mining order, and not actual feerate comparisons, use `getblocktemplate`, not `getrawmempool`.
Pieter Wuille
CC BY-SA 4.0
2023-06-12T12:41:43.320Z
2023-06-12T12:41:43.320Z
Pieter Wuille
<p>I want to get the mempool data ordered by sat/vbyte to understand which transaction will be confirmed.</p>
<p>In order to get the mempool txs I use: &quot;bitcoin-cli getrawmempool&quot; in command prompt. The query returns a string array of txs. But this string array is not ordered by sat/vbyte. How can I order this Txs to understand which transaction will be confirmed in what order?</p>

<bitcoin-core><bitcoind><mempool>
How to get mempool tx ordered by sat/vbyte
Gencehan ARPAÇAY
# How to get mempool tx ordered by sat/vbyte

(Asked by: username_0 on 2023-06-12)

I want to get the mempool data ordered by sat/vbyte to understand which transaction will be confirmed.

In order to get the mempool txs I use: "bitcoin-cli getrawmempool" in command prompt. The query returns a string array of txs. But this string array is not ordered by sat/vbyte. How can I order this Txs to understand which transaction will be confirmed in what order?

**Tags:** bitcoin-core, bitcoind, mempool


---

## 1 answers

### Answer by username_1 on 2023-06-12. Score: 3 | Accepted answer

> I want to get the mempool data ordered by sat/vbyte to understand which transaction will be confirmed.

These two questions are not identical.

While of course mining prefers higher fees over lower fees, there are some reasons why the mining order is not exactly high to low fee:

* Dependencies: when a transaction A in the mempool spends an output of transaction B which is also in the mempool, then B must go into the block before A can. In practice, Bitcoin Core does take such dependencies into account to some extent: if A has a higher feerate than B, then the combination of A and B are treated as a single package, so that B "pays for" A, possibly bumping up A's mining priority.
* Tail effects: near the "end" of a block, it's possible that the highest feerate transaction is too large to fit in the block. In that case the problem of block template building becomes a bin-packing problem, and may include whatever fits.

To answer your question:

* If you want the mempool transactions sorted by fee/vbyte, use `getrawmempool`, and sort the result yourself by feerate. You could do this using `jq` for example:

  ```
  bitcoin-cli getrawmempool true | jq '[to_entries[] | .value] | sort_by(.fees.modified / .vsize)'

  ```
* If you want the (order in which) transactions will end up in a block, use `getblocktemplate` (which is the RPC that mining pools use to get information of block transactions from Bitcoin Core):

  ```
  bitcoin-cli getblocktemplate '{"rules":["segwit"]}

  ```

> **Comments:**
> **username_0**: bitcoin-cli getrawmempool true | jq '[to_entries[] | .value] | sort_by(.fees.modified / .vsize)' this method works but I also need to find the transaction hex but that data is not embeded in this query response  how can I also get the hex of each transaction  
> **username_1**: Try using `bitcoin-cli getrawmempool true | jq -r '[to_entries[] | .value + {"txid":.key}] | sort_by(.fees.modified / .vsize) | .[] | .txid'`.  
> **username_0**: Due to child pay for parent effective fee rates could be smaller but due to higher sat/vbyte these txs are ordered and therefore a transaction which wont be confirmed is being listed in the tx array how can I prevent this  
> **username_1**: @username_0 As I said, if you want the mining order, and not actual feerate comparisons, use `getblocktemplate`, not `getrawmempool`.  

---

