In wallet applications, enabling users to clearly understand real-time transaction status and maintain control is crucial. This enhances certainty and improves user experience. Transaction management is a vital feature—today, we'll explore how wallet apps can manage sent transactions (e.g., canceling or speeding up transactions) and monitor the Mempool to identify stuck on-chain transactions.
The Problem of Low Gas Fees
Most wallet apps allow users to set custom Gas Fees for transactions. While this helps save costs, setting fees too low can leave transactions in a Pending state for extended periods (e.g., days). Platforms like Etherscan display these pending transactions:
Pending Transaction Example:
- Tx Hash: [0x...123]
- Gas Price: 10 Gwei (Recommended: 24 Gwei)
- Status: Pending (>1 hour) Sites like TxStreet visualize real-time blockchain activity, showing pending transactions across networks (e.g., Ethereum currently has 75,000+ pending transactions).
Managing Pending Transactions
Solution: Estimate confirmation times using APIs like Etherscan’s gasestimate:
# Example API Response:
{
"20 Gwei": ">1 hour",
"25 Gwei": "95 seconds",
"30 Gwei": "45 seconds"
} Integrating this logic into wallet apps keeps users informed.
Avoiding Nonce Conflicts
When users send multiple transactions in succession, ensure new transactions don’t reuse the same Nonce as pending ones. Ethereum’s eth_getTransactionCount with pending parameter helps:
// RPC Call Example:
eth_getTransactionCount("0xuserAddress", "pending") This counts pending transactions, preventing accidental overwrites.
Canceling or Accelerating Transactions
Cancel a Transaction
Send a zero-value ETH transfer with:
- Same Nonce as the pending transaction.
- Higher Gas Fee (minimum +10%) to override the original.
// Dart Code Example:
Future<void> sendCancelTransaction({
required EthPrivateKey privateKey,
required int nonce,
required EtherAmount lastGasPrice,
}) async {
final newGasPrice = lastGasPrice * 1.2; // +20%
final cancelTx = Transaction(
to: privateKey.address,
value: EtherAmount.zero(),
nonce: nonce,
maxFeePerGas: newGasPrice,
);
await sendRawTransaction(cancelTx);
} Speed Up a Transaction
Resend the original transaction with increased Gas Fees.
Monitoring the Mempool
The Mempool stores broadcasted but unconfirmed transactions. Services like Blocknative provide APIs to track pending transactions:
Key Features:
- Address Filtering: Monitor specific contracts (e.g., USDT).
- Custom Alerts: Detect function calls or sender addresses.
👉 Explore Blocknative’s Mempool Tools
FAQ
Q1: Why does my transaction stay pending?
A: Low Gas Fees delay confirmation until network fees drop.
Q2: How can I cancel a stuck transaction?
A: Send a zero-ETH transaction with the same Nonce and higher Gas.
Q3: What’s MEV in Mempool?
A: Miners exploit visible transactions for profit (e.g., front-running).
Conclusion
Today covered transaction management (cancel/speed-up) and Mempool monitoring tools like Blocknative. Tomorrow, we’ll implement WalletConnect in apps.