Skip to main content

Try it Live

Run MaxFeePerGas examples in the interactive playground

MaxFeePerGas

EIP-1559 maximum fee per gas representing the maximum total gas price a user is willing to pay for transaction inclusion. Must be >= baseFeePerGas + maxPriorityFeePerGas for transaction to be included.

Overview

Branded bigint type representing max fee in Wei. Acts as a cap on total gas spending. Excess (maxFee - actualPrice) is refunded to sender.

Quick Start

Type Definition

Branded bigint preventing confusion with other fee types. All values in Wei.

API

Construction

from(value)

Create from bigint, number, or hex string.

fromGwei(gwei)

Create from Gwei value.

fromWei(wei)

Create from Wei value (alias for from).

Conversion

toGwei(maxFee)

Convert to Gwei.

toWei(maxFee)

Convert to Wei (identity).

toNumber(maxFee)

Convert to number. Warning: precision loss on large values.

toBigInt(maxFee)

Convert to bigint (identity).

Comparison

equals(maxFee1, maxFee2)

Check equality.

compare(maxFee1, maxFee2)

Compare values. Returns -1, 0, or 1.

Fee Setting Strategies

Conservative

Set maxFee slightly above current base fee:

Normal

Set maxFee with reasonable headroom:

Aggressive

Set high maxFee for guaranteed inclusion:

Real-world Examples

Transaction Submission

Fee Validation

Fee Estimation

Common Patterns

Fee Levels

Dynamic Adjustment

Refund Mechanics

Unused portion of maxFee is refunded:

Specification