Skip to main content

Overview

Gas provides branded types for gas limits and gas prices, preventing common bugs like mixing these values. Includes GasLimit for transaction gas limits and GasPrice for gas prices in wei.

Type Definitions

Both types wrap bigint with branding to prevent accidental mixing.

GasLimit

Creating GasLimit

from

Create from number, bigint, or hex string.

GasLimit Constants

Pre-defined gas limits for common operations:

GasLimit Methods

toBigInt

Convert to bigint.

toNumber

Convert to number.

GasPrice

Creating GasPrice

from

Create from wei value (number, bigint, or hex string).

fromGwei

Create from gwei (more convenient for typical gas prices).

GasPrice Methods

toBigInt

Convert to bigint (wei).

toGwei

Convert to gwei.

Fee Calculation

Calculate transaction fees with type safety:

Common Gas Limits

EIP-1559 Gas Model

Post-London fork, gas pricing uses:
Actual gas price in EIP-1559 is: min(maxFeePerGas, baseFee + maxPriorityFeePerGas)

Namespace Usage

See Also