Skip to main content

How to Access Bitcoin Mempool

Updated on
Dec 11, 2023

7 min read

Overview

Bitcoin is the father of blockchain technology. With Bitcoin started a new era of blockchain and decentralization. Bitcoin enabled everyone to make the peer-to-peer transactions they enjoy today; this guide will teach you how to get these transactions from the Bitcoin mempool.

Prerequisites:

  • Terminal/cmd (CLI).
  • Bitcoin Node.
  • Love for decentralization.

What is Bitcoin Mempool?

The transactions which are sent on the Bitcoin Network are not added directly to the blockchain. All of the valid transactions have to enter a waiting area before they are accepted in a block. This waiting area is known as the mempool. If the size of the mempool is large, it indicates high traffic on the network which results in longer transaction confirmation times and higher transaction fees.

Note: In standard practice, Bitcoin is protocol/network, and bitcoin or BTC is the currency.

The Bitcoin transaction fee is measured in the number of satoshis paid for per byte of the transaction. Satoshi is the smallest unit of the native currency bitcoin of the Bitcoin network, where 1 bitcoin = 100 Million satoshis. Miners give priority to the transactions in the mempool with high transaction fees. But since the SegWit upgrade, a few things changed around Bitcoin transactions. It introduced a new transaction known as a SegWit transaction to increase the number of transactions per Bitcoin block. It fixed two issues: 1. It increased the number of transactions on Bitcoin per second, 2. It fixed the issue of transaction malleability.

Before SegWit, blocks or transactions were measured in bytes, and each block was limited to 1 MB (MegaByte) or 1 Million bytes. After SegWit, transactions, and blocks are measured in weight units; these weight units are used to measure Bitcoin data and compare transactions.

The next concept to cover is vByte. A vByte is equivalent to four 4 weight units. A Byte of data takes 1 vByte (4 weight units) for a legacy transaction. Whereas, for a SegWit transaction, a Byte of data takes 1/4 vByte (1 weight unit). This discount allows the blocks to be filled with 4 times more transactions. The current Bitcoin block size is limited to 1 vMegabyte/ 1 million vByte/ 4 million weight units. Most wallets calculate transaction fees in terms of satoshis/vByte, which is paid per vByte of data used.

Bitcoin mempool analysis use cases:

Mempool analysis helps us understand the congestion/traffic on the network, which ultimately helps us calculating transaction fees.

Let us now access the mempool and get some transactions data from the pool.

Setting Up a QuickNode Bitcoin Endpoint

For our purpose today, we need a Bitcoin node to access the blockchain data. Launching our own node here will be very expensive and time-consuming, given the large amount of data on Bitcoin. We will instead sign up with a free QuickNode account here where we will be able to easily create a Bitcoin endpoint.

Screenshot of Quicknode Bitcoin endpoint

Copy and save the HTTPS URL of your node as it will be needed later.

How to access Bitcoin Mempool/How to get pending transactions from Bitcoin

We will use Bitcoin RPC methods to get mempool data getrawmempool method to be specific Open terminal/cmd and copy-paste the following:

curl --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "getrawmempool", "params": [true]}' -H 'content-type: application/json' <QUICKNODE_BITCOIN_URL>

Replace QUICKNODE_BITCOIN_URL with your Bitcoin node’s HTTPS URL, which we got in the last step. Above is a cURL request to our node along with the getrawmempool method. 

The output should be similar to this.

Now let us understand the output body. The above method gives out a list of pending transactions currently in the mempool. We will take out a single transaction and go through each field.

{
"result": {
"2d1228abf06836b1173936061fec0384e82e3b684d7950a27f06a06f587400d3": {
"fees": {
"base": 0.00111999,
"modified": 0.00111999,
"ancestor": 0.00111999,
"descendant": 0.00111999
},
"size": 90826,
"fee": 0.00111999,
"modifiedfee": 0.00111999,
"time": 1629052793,
"height": 695936,
"descendantcount": 1,
"descendantsize": 90826,
"descendantfees": 111999,
"ancestorcount": 1,
"ancestorsize": 90826,
"ancestorfees": 111999,
"wtxid": "b3b49bb3dcae483d579710a2e1f9c7ed585ab35e2a8cb941ff8cb27ea8adec20",
"depends": [],
"spentby": [],
"bip125-replaceable": false
}
}
}

Explanation of the above JSON output:

Line 3: This is the transaction id by which a transaction on the blockchain is identified.

Line 4-9: Transaction fee breakdown.

Line 10: Size of the transaction as per BIP 141.

Line 11: Transaction fee in BTC (bitcoin).

Line 12: Transaction fee with fee deltas used for mining priority.

Line 13: Time at which the transaction entered in the pool in seconds since 1 Jan 1970 GMT.

Line 14: Height of the blockchain (latest block) when transaction entered the pool.

Line 15: Number of descendent transactions in mempool, including this one.

Line 16: Size of all the descendent transactions in mempool.

Line 17: Modified fees of all the descendent transactions in mempool.

Line 18: Number of ancestor transactions in mempool, including this one.

Line 19: Size of all the ancestor transactions in mempool.

Line 20: Modified fees of all the ancestor transactions in mempool.

Line 21: Transaction id along with witness data.

Line 22: If an unconfirmed transaction is used as input for this transaction, it is to be entered here.

Line 23: If another unconfirmed transaction is using data from this transaction, it must be entered here.

Line 24: A Boolean value showing that whether the transaction can be replaced due to BIP 125.

Now to get the actual transaction data we will have to use another method getrawtransaction which will return information about a particular transaction. Copy-paste the following in your terminal/cmd:

curl --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "getrawtransaction", "params": ["2d1228abf06836b1173936061fec0384e82e3b684d7950a27f06a06f587400d3", true]}' -H 'content-type: application/json' <QUICKNODE_BITCOIN_URL>

Replace QUICKNODE_BITCOIN_URL with your Bitcoin node’s HTTPS URL, which we got in the last step. Above is a cURL request to our node along with the getrawtransaction method. To get this, we will ping our node to resolve the method. We have to pass two parameters for this method. The first is the transaction id of the transaction to be queried. The second is a boolean value which, if set false, returns a string; otherwise, it returns a JSON object.

We have set the second parameter as ‘true’, so the output should look like this.

Explanation of the transaction object pasted here:

Line 3: Transaction id by which a transaction on the blockchain is identified (same as provided).

Line 4: Transaction hash which from txid for witness transactions.

Line 5: Size of the transaction as per BIP 141.

Line 6: Virtual size of the transaction which from size for witness transactions.

Line 7: The version number of the transaction, currently 1 or 2. If 2, it means BIP 68 applies.

Line 8: Lock time is specified as a block number. If a lock time is mentioned, then that transaction can only be added to a block if the lock time block has been passed. For example, if the lock time is mentioned as 30, miners can only pick up the transaction after block number 30 has been mined.

Line 9-20: Vin shows the list of transactions in mempool this particular transaction is using as input.

Line 21-33: Vout shows the list of transactions in mempool using this particular transaction as input.

Line 34: Block hash, null here as the transaction is not confirmed yet.

Line 35: Number of confirmations the transaction has passed.

Line 36: Time at which the transaction entered in the pool in seconds since 1 Jan 1970 GMT.

Line 37: Time at which block was mined in which the transaction was added, null here since the transaction is pending.

Line 38: Serialized, hex-encoded data for 'txid'

By analyzing the above data we can understand in and outs of a Bitcoin transaction. Bitcoin transactions are pretty complex, but getrawtransaction method gives out the raw transaction information which is easy to look at and understand.

Conclusion

Congratulations on mastering the Bitcoin mempool. Today in this guide, we learned what Bitcoin mempool is, the use of Bitcoin mempool, how to access Bitcoin mempool/how to get Bitcoin pending transactions, and how to get Bitcoin pending transaction data.

Subscribe to our newsletter for more articles and guides on Ethereum. If you have any feedback, feel free to reach out to us via Twitter. You can always chat with us on our Discord community server, featuring some of the coolest developers you’ll ever meet :)

Share this guide