Monitoring the Cardano Mempool using Cardano-CLI

The Cardano mempool is where unconfirmed transactions wait to be included in the next block. Monitoring the mempool can provide valuable insights into network activity and transaction fees. With the cardano-cli command line interface, you can easily observe the mempool in real time. Here's how to monitor Cardano's mempool using cardano-cli.

Getting Started with Cardano-CLI

To monitor the mempool, you'll first need to have cardano-cli installed and synced up with the Cardano network. Cardano-cli comes standard with Cardano node implementations like cnode. Follow the setup instructions for your node to install cardano-cli.

Once installed, you can sync cardano-cli to the network with:

Copy codecardano-cli query tip --mainnet

This queries the latest block from the network so cardano-cli has up-to-date blockchain data.

Viewing the Mempool Contents

The main command for checking mempool contents is:

Copy codecardano-cli query utxo --mainnet --mary-era

This will display all unspent transaction outputs currently in the mempool. Each output shows the transaction hash, address, value in lovelace, and other metadata.

Scrolling through the full output can be cumbersome. To view a summarized count, add the --count flag:

Copy codecardano-cli query utxo --mainnet --mary-era --count

This prints the total number of mempool entries. Monitor this over time to see transaction volume ebb and flow.

Checking Mempool Stats

Beyond just entries, cardano-cli can provide stats on the overall mempool:

Copy codecardano-cli query utxo-stats --mainnet --mary-era

Notable stats include:

  • num_txs - Total number of transactions in the mempool currently
  • txs_size - Total size in bytes of those transactions
  • min_fee - Lowest transaction fee rate currently in the mempool
  • max_fee - Highest transaction fee rate currently in the mempool
  • med_fee - Median transaction fee rate

Check these periodically to gauge mempool demand. Higher median fees indicate congestion and competition for block space.

Monitoring Transaction Fees

Since transactions compete by fees to enter the next block, monitoring the fee distribution is helpful.

To sample fees for transactions currently in the mempool, use:

Copy codecardano-cli query utxo-stats --mainnet --mary-era --fees

This groups unconfirmed transactions by their fee rate. You can see the percentage of the mempool at each fee level.

When the mempool is congested, you'll see the distribution skew towards higher fees. This gives a real-time view into the fees required for quick confirmation.

"As a Cardano enthusiast, seeing the mempool ebb and flow feels like taking the pulse of the blockchain. When activity spikes, it's exciting to see the network thriving. Monitoring the metrics provides an insider's view into the state of the chain."

Using Mempool Data

With an eye on the mempool, you can better understand the optimal transaction fees to use:

  • If fees are low, you can save on fees and still have relatively quick confirmations
  • When average fees rise, increase your transaction fees accordingly to ensure prompt inclusion

You can also predict when network usage and fees might be elevated, like during NFT minting frenzies. Planning transactions during less busy periods can save on fees.

Monitoring Mempool from a Node

The above commands require having cardano-cli installed locally. For convenience, you can also monitor mempool stats using public Cardano nodes. Services like CardanoScan have API endpoints that expose mempool data.

Some examples:

  • https://cardanoscan.io/apis/v1/mempool - Gives mempool summary stats
  • https://cardanoscan.io/apis/v1/mempool/fees - Samples current fee distribution
  • https://cardanoscan.io/apis/v1/mempool/txs - Lists current mempool transactions

Using these public nodes, you can easily build mempool monitoring into your own app or dashboard!

How can I optimize transaction fees based on mempool data?

When sending transactions on Cardano, you want your tx to be included in the next block or two. By optimizing your fees based on current mempool conditions, you can achieve fast confirmations without overpaying. Here are some tips:

  • Check the median transaction fee in the mempool using cardano-cli query utxo-stats --mary-era --mainnet --fees. Aim to set your fee above the median.
  • During congestion, check the upper percentile fees (75th, 90th percentiles). You may need to set fees that high for quick confirmation.
  • For large transactions, aim for higher fees than average since your tx will take more block space.
  • Use services like Mempool.Space to see recent average fees for confirmation within 1-3 blocks. Target that fee level.
  • Set fee higher during spikes in mempool transactions or NFT minting frenzies. Lower when mempool is emptier.
  • Overpaying fees is unnecessary. Check mempool frequently and lower your fee as congestion decreases.

With dynamic fee setting informed by mempool data, you can optimize cost while still seeing fast confirmations under 10 minutes. Monitoring mempool stats helps you save ADA!

How can DApp developers optimize for mempool conditions?

For DApps operating on Cardano, accounting for real-time mempool conditions can improve the user experience and save costs. Here are some tips for developers:

  • Check mempool stats before triggering transactions. Avoid sending when congested if possible.
  • Batch transactions during lower activity periods to reduce fees.
  • If batched transactions are over the standard block size, split into smaller groups.
  • Set higher default fees during NFT drops or other mempool spikes to ensure users transact smoothly.
  • Display current optimal fees to users so they understand costs. Allow fee setting overrides.
  • Let users defer less urgent transactions until mempool clears rather than overpaying fees.
  • Consider mempool-based dynamic fees for transactions rather than fixed fees.
  • Set higher than average fees for smart contract transactions which are larger in size.

By proactively managing fees, developers can create DApps that work seamlessly despite mempool fluctuations. Check services like Mempool.Space for current data.

Conclusion

Monitoring Cardano's mempool provides valuable transparency into the blockchain's usage and congestion. With cardano-cli, you can easily observe mempool stats, optimal fees, and transaction demand in real time.

As a user, this helps you save on fees by sending during less busy periods and accurately pricing based on prevailing rates. Developers can build DApps that account for changing mempool conditions to optimize costs and the user experience.

By keeping an eye on the mempool ebb and flow, anyone can gain insights into the heartbeat of Cardano. Mempool monitoring offers a window into the blockchain in action.

Check our guide of the most promising crypto

Read more