September 21, 2022
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:
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. 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.Note: In standard practice, Bitcoin is protocol/network, and bitcoin or BTC is the currency.
Booting a Bitcoin node
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 get a free trial Bitcoin node from QuickNode. 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: how to access bitcoin mempool how to get pending transactions from bitcoin 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. how to access bitcoin mempool how to get pending transactions from bitcoin {"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: how to access bitcoin mempool how to get pending transactions from bitcoin 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.curl --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "getrawmempool", "params": [true]}' -H 'content-type: application/json' <QUICKNODE_BITCOIN_URL>
curl --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "getrawmempool", "params": [true]}' -H 'content-type: application/json' <QUICKNODE_BITCOIN_URL>
{ "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 } }}
{ "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 } }}
curl --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "getrawtransaction", "params": ["2d1228abf06836b1173936061fec0384e82e3b684d7950a27f06a06f587400d3", true]}' -H 'content-type: application/json' <QUICKNODE_BITCOIN_URL>
curl --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "getrawtransaction", "params": ["2d1228abf06836b1173936061fec0384e82e3b684d7950a27f06a06f587400d3", true]}' -H 'content-type: application/json' <QUICKNODE_BITCOIN_URL>
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 :)
- Overview
- What is Bitcoin Mempool?
- Booting a Bitcoin node
- How to access Bitcoin Mempool/How to get pending transactions from Bitcoin
- Conclusion
Sahil Sen
Web developer who believes in power of communities and is passionate about community building. Developer evangelist @ QuickNode.
Want more Web3 tutorials?
We'll send you our latest tutorials via the QuickNode Newsletter.
Related articles37
How to generate a new Ethereum address in PHP
Published: Mar 5, 2021
Updated: Sep 9, 2022
PHP is very popular in developing the backend of websites or web applications. PHP has a huge crowd of developers trusting it as their go-to language. In this guide, we will see how we can...
Continue reading
How to do a non-custodial transaction with QuickNode
Published: Jun 19, 2021
Updated: Sep 9, 2022
Private keys are one of the most sensitive pieces of data when it comes to cryptography and the blockchain. However, there has always been debate/confusion about choosing between custodial...
Continue reading
How to stream pending transactions with ethers.js
Published: Feb 13, 2021
Updated: Sep 21, 2022
Here is a video representation of this guide if you prefer to watch instead of read[yt:YjQj6uk9M98]On ethereum, before being included in a block,...
Continue reading
How to generate a new Ethereum address in Ruby
Published: Feb 20, 2021
Updated: Sep 9, 2022
With high usage in web applications and straightforward syntax, Ruby is used by a vast number of people. This guide will cover creating an Ethereum address in Ruby using
Continue reading
How to Set Up a Near Project from Scratch
Published: Jan 27, 2022
Updated: Sep 9, 2022
In this tutorial we will look at how we can setup a basic NEAR project from scratch, installing and configuring dependencies and customizing the project to work well with...
Continue reading
Estimating gas price using pending transactions in Python
Published: Feb 20, 2021
Updated: Sep 9, 2022
To send a transaction on the Ethereum network, you need to pay fees for including the transaction in a block as well as the computation necessary in the transaction; this fee is called gas....
Continue reading
How to Build an NFT Gallery using React and QuickNode's NFT API
Published: Jul 11, 2022
Updated: Sep 9, 2022
Ever wanted to get a list of all the owners of a particular NFT collection? Or wanted to fetch all the metadata for an NFT collection? From experience, you may know that compiling all this NFT...
Continue reading
Como crear y lanzar un ERC-721 (NFT)
Published: Dec 27, 2021
Updated: Sep 9, 2022
Coleccionables digitales que son compatibles con ERC-721 se han vuelto muy populares desde el lanzamiento de Cryptokitties y han ganado adopción...
Continue reading
How to Build Your DApp Using The Modern Ethereum Tech Stack: Hardhat and EthersJs
Published: Dec 21, 2021
Updated: Sep 9, 2022
When building a smart contract on the Ethereum blockchain, new developers tend to reach out to tools like truffle and web3.js in building their smart contracts. This tutorial will look at how...
Continue reading
How to connect to Ethereum network using Java / Web3j
Published: Oct 23, 2020
Updated: Sep 9, 2022
We can say that Java is one of the most versatile languages out there, and it continues to be relevant in today's time. Java is so popular because of its massive user base and use cases. In...
Continue reading
How to connect to Ethereum network with ethers.js
Published: Apr 27, 2020
Updated: Sep 9, 2022
When someone thinks of developing a dApp the first tool that comes to their mind is web3.js which is pretty common because of its popularity in the community and wide use cases, dApp...
Continue reading
How to Create and Deploy a Clarity Smart Contract on the Stacks Blockchain
Published: Aug 19, 2022
Updated: Sep 9, 2022
Stacks is an open-source layer-1 blockchain that utilizes the Proof of Transfer (PoX) consensus mechanism. The Stacks blockchain leverages Bitcoin's security and allows direct read access to...
Continue reading
How to Mint an NFT on Polygon with Ethers.js
Published: Mar 28, 2022
Updated: Oct 19, 2022
This guide demonstrates how to mint an NFT on the Polygon blockchain using the Ethers.js library and our Factory ERC-1155 contract we built in an earlier
Continue reading
How to access Ethereum Mempool
Published: Oct 15, 2020
Updated: Sep 15, 2022
On Ethereum, when a transaction is sent, before being added to a block, it resides in what is called a Mempool. To receive information about this transaction, the Mempool must be queried. This...
Continue reading
Published: Jul 3, 2021
Updated: Sep 15, 2022
A developer stack is a bag of technologies a developer possesses. For example, MEAN (MongoDB, Express.js, AngularJS/Angular, and Node.js) and MERN (MongoDB, Express.js, React, and Node.js) are...
Continue reading
How to Fetch Transaction History on Ethereum using Web3.py
Published: Jun 3, 2022
Updated: Dec 11, 2022
If you are building on Ethereum, you may run into scenarios where you need to fetch transaction history for a given address. Unfortunately, the current design for Ethereum lacks an easy way to...
Continue reading
How to Mint NFTs on the Stacks Blockchain
Published: Aug 19, 2022
Updated: Sep 9, 2022
Stacks is an emerging blockchain secured by Bitcoin and with native support for smart contracts. Our previous Stacks guide demonstrated
Continue reading
How to Mint an NFT Collection using thirdweb
Published: May 13, 2022
Updated: Sep 21, 2022
Building on web3 is sometimes seen as a challenge greater than building on web2. The majority of web2 development features and technologies are well-documented and have stood the test of time,...
Continue reading
Introduction to Scaffold-ETH 🏗
Published: Oct 7, 2021
Updated: Sep 9, 2022
Developing applications involves juggling several moving pieces like front-ends, back-ends, and databases. But developing a decentralized application on a blockchain adds a few more elements...
Continue reading
How to generate a new Bitcoin address in JavaScript
Published: Jun 26, 2021
Updated: Sep 9, 2022
To do any type of transaction on the Bitcoin blockchain, you’ll need a public key or a Bitcoin address. In this guide, we’ll cover how to generate a new Bitcoin address in JavaScript using
Continue reading
How to Create a dApp on Avalanche's Fuji Testnet with QuickNode
Published: Jun 1, 2022
Updated: Sep 9, 2022
Avalanche is an open-source, proof-of-stake blockchain with smart contract functionality that uses the Snow family of consensus protocols. The Avalanche...
Continue reading
How to create your own DAO with Aragon
Published: Aug 8, 2021
Updated: Sep 9, 2022
Blockchain provides us with the power of decentralization. Decentralization means the transfer of power to users/members rather than having a single centralized authority governing everything;...
Continue reading
How to Connect Your Dapp With MetaMask Using Ethers.js
Published: Dec 13, 2021
Updated: Nov 14, 2022
In our dApp, we will have a simple react user interface that has a material button asking the user to connect to MetaMask. And if they do not have an account, they can create one or log in to...
Continue reading
How to re-send a transaction with higher gas price using ethers.js
Published: Sep 23, 2020
Updated: Sep 9, 2022
Sometimes, you submit a transaction on Ethereum without enough gas due to network congestion or too many pending transactions offering a higher gas price than you have offered on your...
Continue reading
How to connect to Ethereum using PHP
Published: Jun 11, 2021
Updated: Sep 9, 2022
PHP is a very popular choice among developers and has a vast community due to its long presence in web development. In this guide, we’ll cover how to connect to Ethereum with PHP using the
Continue reading
How to Build an ERC20 Token Balance App with QuickNode Token API
Published: Oct 26, 2022
Updated: Nov 18, 2022
Making a dApp that requires ERC20 token data can be tedious since there are numerous tokens, and one needs to query each token contract to get the data. This guide will show how we can build a...
Continue reading
How to use Subspace with QuickNode
Published: Sep 8, 2020
Updated: Sep 9, 2022
In this guide, we'll understand a bit about reactive development and how to use Subspace with QuickNode.JavaScript is the programming language behind most of the internet apps and...
Continue reading
How to connect to Ethereum network with Web3.js
Published: May 12, 2020
Updated: Sep 9, 2022
Libraries and frameworks make the development process a lot easier and faster. When it comes to Ethereum development, Web3.js is the go to...
Continue reading
How to Build a One-Click Sign in Using MetaMask with PHP's Laravel
Published: Nov 2, 2021
Updated: Sep 9, 2022
Social logins: we have all seen them, we have all used them. "Login with Facebook". "Login with Github".If you have been around the Web3 community you may have come across a...
Continue reading
How to generate a new Ethereum address in Go
Published: Feb 13, 2021
Updated: Sep 9, 2022
Golang is very popular among backend developers for building infrastructures and microservices. Go is a procedural programming language. Developed in 2007 by...
Continue reading
How to generate a new Ethereum address in Python
Published: Feb 6, 2021
Updated: Sep 9, 2022
Python is one of the most versatile programming languages out there with an abundance of use cases; We can build many applications with Python from client-side to back end. In this guide, we...
Continue reading
How to generate a new Ethereum address in JavaScript
Published: Feb 13, 2021
Updated: Sep 9, 2022
When it comes to programming, there’s hardly anyone who has not used or heard about JavaScript. JavaScript was initially...
Continue reading
How to connect to the Ethereum network usingPython with Web3.py
Published: Apr 5, 2020
Updated: Sep 23, 2022
You can build Ethereum applications in different programming languages. In this article, we will connect to the Ethereum network using...
Continue reading
How to Lazy Mint an NFT on Rarible with Rarepress
Published: Feb 23, 2022
Updated: Sep 9, 2022
NFTs are great for creators to monetize their artwork and for people to get ownership of an item. But since gas prices are usually high given the highly in-demand space on Ethereum, minting an...
Continue reading
Integrate Your Svelte App with a Smart Contract
Published: Dec 20, 2021
Updated: Oct 20, 2022
Today we will be building a sample app in Svelte, and connecting it to a smart contract that we deploy on the Ropsten Network.Our frontend will be able to do the...
Continue reading
How to get the balance of an ERC-20 token
Published: Jun 14, 2021
Updated: Sep 21, 2022
When a new token is made on the Ethereum network, it usually follows a specification. The most popular of which is the ERC20...
Continue reading
Transaction Calldata Demystified: A Guide to Understanding Transaction Calldata on Ethereum
Published: Jan 20, 2023
Updated: Jan 20, 2023
If you’ve interacted with smart contracts on Ethereum before, you might have noticed that your transaction includes a long hexadecimal value in its data field. As a user (or developer), you...
Continue reading