A Builder’s Introduction to the Mempool
Tags: blockchain, ethereum, mempool, defi
Published: 2021-05-14 19:04:13

The mempool is often referenced as a waiting room for pre-chain transactions, but “waiting room” is too passive of a term. It suggests it’s a casual place for transactions to hang out while they wait to be confirmed on-chain. In reality, it’s more like a [](https://www.blocknative.com/blog/mempool-forensics) [battle zone](https://www.blocknative.com/blog/mempool-forensics). Bots can force their way in to exploit arbitrage opportunities. Transactions can change out of sight, leaving you and your traders unprepared for battle.

Traders are your end-users, so you are building for them. The more attractive you can make your product, the more traders you will have transacting on your Dapp (decentralized application). To get ahead as a builder, you need to understand the conditions of transaction fees (gas) and replacement transactions—and the data for this required knowledge lives in the mempool.

## Enter the mempool

Or should we say [mempools](https://www.blocknative.com/blog/8-lesson-master-the-mempool)[](https://www.blocknative.com/blog/8-lesson-master-the-mempool)? Complicating all of this is the fact that there is no single source of truth for the mempool. “The mempool” can be a misleading phrase to those new to smart contracts and the [Ethereum](https://ethereum.org/en/)[](https://ethereum.org/en/) ecosystem. There is not just one mempool; every node has its own version, so there are as many mempools as there are [nodes](https://www.blocknative.com/blog/mempool-nodes)[](https://www.blocknative.com/blog/mempool-nodes).

Transactions enter the mempool with a competitive gas fee, which is attractive to miners so they will include it in a block. A low gas fee can result in extended wait times for on-chain confirmation, but there are other factors to be cognizant of that could leave a transaction hanging—or worse—stuck.

If the network becomes too crowded, gas prices can increase, rendering existing transactions uncompetitive. Transactions get priced out. Uncompetitive transactions get dropped by miner nodes. These dropped transactions can disappear from the mempool and are hard to keep track of without extensive engineering work and infrastructure.

When transactions get dropped, new transactions originating from that wallet address can result in a [stuck transaction](https://www.blocknative.com/blog/mempool-forensics)[](https://www.blocknative.com/blog/mempool-forensics)—due to a nonce gap. With a stuck transaction, a wallet can’t process other transactions until the nonce gap is resolved. For a trader, these scenarios create perplexing user experiences in Dapps. Traders, especially inexperienced ones, might expect updates from the UI about what is happening to their transactions. But without mempool data, your Dapp doesn’t know what is going on behind the scenes, leaving the trader oblivious to the circumstances.

Understanding the mempool and how to use the data to your advantage will be a boon to building DeFi or NFT Dapps that people want to use. 

## The very real variables in mempool “immutability”

The mempool is an open arena for transactions. The goal is to get a transaction confirmed both quickly and for the right price. You’ve built a Dapp to facilitate this process for traders, but what does it actually know about the arena?

The word “immutable” gets thrown around when speaking about blockchain technology, but it’s a word that should be used carefully. In truth, there are variables and actions that can change the course of a transaction. Everything in the mempool can be overwritten, and in this case, your Dapp is left in the dark.

Your Dapp will know about buying, pending, and confirmed transactions. Emphasis on the _pending_. While a transaction is in the mempool, traders can alter the process inside a wallet, which exists outside the knowledge of your Dapp, bypassing it completely.

Two ways a trader can alter transactions are:

1.  [Speed Ups](https://www.blocknative.com/blog/speed-up-transactions)[](https://www.blocknative.com/blog/speed-up-transactions)
2.  [Cancels](https://www.blocknative.com/blog/canceled-transactions)

In a Speed Up, a trader can attempt to overwrite a pending transaction with a new transaction. A trader has realized their gas fee is too uncompetitive. They enter an identical transaction with a higher gas fee to get it in a block faster than the original transaction.

In a Cancel Transaction, a trader can attempt to overwrite a pending transaction with a zero-dollar transaction. Similar to a Speed Up, they can enter a higher gas fee to get the Cancel Transaction in a block faster than the original transaction.

Both Speed Ups and Cancel Transactions create new hashes—this situation is outside the scope of your Dapp without the proper data from the mempool. When Speed Ups and Cancel Transactions are successful, they leave the incomplete original transactions hanging around in your UI with nowhere to go.

## Navigating gas prices and transactions

High fees result in less profit. Low fees result in delays, failed transactions, and stuck wallets. What does this mean for builders? Gas fees can eat into protocol margins and disincentivize users from transacting.

As a builder, you want to provide accurate gas price guidance so that your users have a positive experience. And by helping your users accurately set gas prices, you will avoid the UX headaches that we described above. 

[Gas prices](https://www.blocknative.com/blog/estimate-gas-prices)[](https://www.blocknative.com/blog/estimate-gas-prices) are not just important for traders to understand, but they are equally important for builders to understand. Navigating gas fees can be difficult for traders and builders of all levels. By providing gas price information to traders, you can lessen their transaction anxiety and give them a competitive edge in the [mempool marketplace](https://www.blocknative.com/blog/why-the-mempool-matters)[](https://www.blocknative.com/blog/why-the-mempool-matters). But finding that goldilocks solution between delays and missed profits is difficult.

After a transaction has entered the mempool, the gas price could fluctuate. If it does, gas fees on pending transactions become unattractive to miners looking to make the most profit. By providing accurate gas price guidance, you equip your users to trade with confidence.

Looking at the last confirmed block kind-of-sort-of gives you an estimation of reasonable current gas fees. But blocks have limited space for transaction records, which leads to congestion. If there is more demand for transactions than blockchain capacity, the last block is not a reliable source of information. The fluctuation in gas price between blocks could be considerable, and you could end up providing incorrect information to traders.

Current mempool data is a more reliable source of information. While this is more reliable, it’s also a lot more work, requiring serious engineering efforts. You will need to monitor the gas price distribution of the mempool in real-time. 

## Work with mempool data in real-time

If you are a builder, you have end-users. Some of them might be retail buyers ([such as NFTs](https://www.blocknative.com/blog/mintable-interview)[](https://www.blocknative.com/blog/mintable-interview)), while others might be more sophisticated [DeFi](https://www.blocknative.com/defi)[](https://www.blocknative.com/defi) traders running bots. Regardless, you have _people_ on the other end who are interested in exploring and using your new creation. Building mempool data into your Dapp will make it a more attractive product to traders.

Monitoring the mempool doesn’t need to take up all your engineering efforts. [Mempool Explorer](https://www.blocknative.com/explorer)[](https://www.blocknative.com/explorer) is easy to integrate and provides real-time transaction event streams by looking at thousands of data points every second. For example, you can easily monitor top pairs on [Uniswap](https://www.blocknative.com/uniswap)[](https://www.blocknative.com/uniswap), [Honeyswap](https://www.blocknative.com/asset/hny)[](https://www.blocknative.com/asset/hny), or [PancakeSwap](https://www.blocknative.com/asset/cake)[](https://www.blocknative.com/asset/cake). 

[Gas Platform](https://www.blocknative.com/gas-platform)[](https://www.blocknative.com/gas-platform) is a gas fee API, accurately estimating Ethereum transaction fees based on what is currently in the mempool.

We have an active discord community, so if you’d like to be a part of the conversation, [join us here](https://discord.com/invite/KZaBVME)[](https://discord.com/invite/KZaBVME).