Gas Optimization

Reduce transaction costs by 35% with dynamic fee strategies, priority bidding, and MEV protection.

Overview

Molt402's gas optimizer analyzes network conditions in real-time to calculate optimal fee parameters. Instead of overpaying for guaranteed inclusion or underpaying and waiting indefinitely, the optimizer finds the efficiency frontier for each urgency level.

How it works

The optimizer implements three core strategies:

Base fee prediction: Exponential moving average of recent blocks predicts next-block base fee with 95% confidence Priority fee bidding: Historical analysis determines competitive priority fees for each urgency tier Dynamic adjustment: Automatic gas price bumping when transactions don't confirm within expected timeframe

Urgency tiers

Instant

Target next-block inclusion (12-15 seconds).

const result = await client.execute({
  instruction: "Transfer 50 USDC to 0xabcd...ef01",
  urgency: "instant"
})

Fee strategy:

  • Base fee: 98th percentile prediction (near-certain inclusion)

  • Priority fee: 95th percentile (compete with high-priority transactions)

  • Use case: Time-sensitive arbitrage, liquidations, critical operations

Cost premium: +40% vs standard tier Confirmation probability: >95% next block

Fast

Target inclusion within 3 blocks (~45 seconds).

Fee strategy:

  • Base fee: 90th percentile prediction

  • Priority fee: 75th percentile

  • Use case: User-facing operations, moderate time sensitivity

Cost premium: +15% vs standard tier Confirmation probability: >90% within 3 blocks

Standard (default)

Target inclusion within 10 blocks (~2 minutes).

Fee strategy:

  • Base fee: 75th percentile prediction

  • Priority fee: 50th percentile (median)

  • Use case: Most operations, balanced cost/speed trade-off

Cost premium: Baseline Confirmation probability: >85% within 10 blocks

Economy

Best-effort inclusion, minimize cost.

Fee strategy:

  • Base fee: 50th percentile prediction

  • Priority fee: 25th percentile (below median)

  • Use case: Non-urgent background operations

Cost saving: -30% vs standard tier Confirmation probability: >70% within 20 blocks (variable timing)

Manual gas configuration

Override automatic optimization for specific requirements:

When to use manual config:

  • Strict budget constraints

  • Custom timing requirements

  • Testing gas strategies

  • Compliance with protocol limits

Warning: Manual configuration may result in delayed or failed inclusion if fees are insufficient.

Dynamic adjustment

If transaction doesn't confirm within expected timeframe, Molt402 automatically bumps gas price.

Exponential strategy:

  1. Initial: 50 gwei

  2. Bump 1 (+20%): 60 gwei

  3. Bump 2 (+20%): 72 gwei

  4. Bump 3 (+20%): 86.4 gwei

Linear strategy:

  1. Initial: 50 gwei

  2. Bump 1 (+10 gwei): 60 gwei

  3. Bump 2 (+10 gwei): 70 gwei

  4. Bump 3 (+10 gwei): 80 gwei

MEV protection

Prevent frontrunning and sandwich attacks with private transaction relays.

Configuration

Supported providers

Flashbots: Largest private mempool, highest liquidity Eden Network: Priority ordering, MEV redistribution bloXroute: Low latency, global coverage

When to use MEV protection

Enable for:

  • DEX swaps >$1000

  • NFT purchases

  • Liquidation transactions

  • Time-sensitive arbitrage

Skip for:

  • Simple transfers

  • Low-value transactions (<$100)

  • Operations not susceptible to MEV

Costs

Private relays charge priority fees or percentage of MEV value. Molt402 automatically selects the most cost-effective relay for each transaction.

Gas estimation

Accurate gas limit estimation prevents wasted funds from out-of-gas failures.

Automatic estimation

Molt402 simulates transactions to estimate exact gas usage:

Estimation process:

  1. Simulate transaction against current state

  2. Measure actual gas consumption

  3. Add 10% buffer for state changes

  4. Cap at block gas limit

Manual gas limits

Override estimation for special cases:

When to set manual limits:

  • Complex contracts with variable gas usage

  • Multi-step operations

  • Testing worst-case scenarios

Cost analysis

Example comparison

Transfer 50 USDC on x402 mainnet:

Urgency
Base Fee
Priority Fee
Total Fee
USD Cost
Time

Instant

48 gwei

4 gwei

52 gwei

$3.64

~15s

Fast

45 gwei

2.5 gwei

47.5 gwei

$3.33

~45s

Standard

43 gwei

1.5 gwei

44.5 gwei

$3.12

~2min

Economy

40 gwei

0.5 gwei

40.5 gwei

$2.84

~4min

Savings: Economy tier saves $0.80 (22%) vs instant, acceptable for non-urgent operations.

Cost optimization strategies

Batch transactions: Amortize fixed costs across multiple operations

Off-peak execution: Schedule non-urgent operations during low-congestion periods

Monitor historical patterns: Identify low-cost time windows

Monitoring gas spend

Track cumulative gas costs to identify optimization opportunities.

Real-time tracking

Historical analysis

Advanced optimization

EIP-1559 prediction models

Molt402 uses machine learning to predict base fee trends:

ML model: LSTM neural network trained on historical base fee patterns Statistical model: Exponential weighted moving average (faster, less accurate)

Flash loan optimization

Reduce gas costs for flash loan operations:

Optimization techniques:

  • Calldata compression (save ~2000 gas per transaction)

  • Gas token refunds (CHI, GST2)

  • Optimal operation ordering

  • Redundant approval elimination

Troubleshooting

Transaction stuck in pending

Problem: Transaction not confirming despite adequate gas price.

Solution: Increase urgency tier or manually bump gas

Out-of-gas errors

Problem: Transaction reverts due to insufficient gas limit.

Solution: Enable simulation or increase manual gas limit

High gas costs

Problem: Gas costs exceeding budget.

Solution: Use economy tier, batch operations, or schedule off-peak

Best practices

Use appropriate urgency: Don't pay for instant when standard suffices Enable simulation: Accurate gas estimation prevents waste Batch operations: Amortize fixed costs across multiple transactions Monitor gas spend: Set alerts for unusual consumption Schedule off-peak: Execute non-urgent operations during low congestion Test on testnet: Validate gas optimization before mainnet deployment

Next steps

Support

Questions about gas optimization? We're here to help:

Last updated