Skip to main content
@tevm/voltaire
@tevm/voltaire / primitives/EffectiveGasPrice

primitives/EffectiveGasPrice

Type Aliases

EffectiveGasPriceType

EffectiveGasPriceType = bigint & object
Defined in: src/primitives/EffectiveGasPrice/EffectiveGasPriceType.ts:10 Branded EffectiveGasPrice type - EIP-1559 effective gas price Represents the actual gas price paid in a transaction Calculated as: min(baseFee + priorityFee, maxFeePerGas)

Type Declaration

[brand]
readonly [brand]: "EffectiveGasPrice"

See

https://eips.ethereum.org/EIPS/eip-1559

Variables

EffectiveGasPrice

const EffectiveGasPrice: object
Defined in: src/primitives/EffectiveGasPrice/index.ts:54

Type Declaration

calculate()
calculate: (baseFee, maxFee, maxPriorityFee) => EffectiveGasPriceType
Calculate effective gas price from EIP-1559 fee parameters Formula: min(baseFee + min(maxPriorityFee, maxFee - baseFee), maxFee)
Parameters
baseFee
bigint Base fee per gas
maxFee
bigint Maximum fee per gas
maxPriorityFee
bigint Maximum priority fee per gas
Returns
EffectiveGasPriceType Effective gas price
Example
const baseFee = 25000000000n; // 25 Gwei
const maxFee = 100000000000n; // 100 Gwei
const maxPriorityFee = 2000000000n; // 2 Gwei
const effective = EffectiveGasPrice.calculate(baseFee, maxFee, maxPriorityFee);
// Returns 27000000000n (25 + 2 Gwei)
compare()
compare: (effectivePrice1, effectivePrice2) => number
Parameters
effectivePrice1
string | number | bigint
effectivePrice2
string | number | bigint
Returns
number
equals()
equals: (effectivePrice1, effectivePrice2) => boolean
Parameters
effectivePrice1
string | number | bigint
effectivePrice2
string | number | bigint
Returns
boolean
from()
from: (value) => EffectiveGasPriceType
Create EffectiveGasPrice from bigint, number, or hex string
Parameters
value
Effective price in Wei string | number | bigint
Returns
EffectiveGasPriceType Branded effective gas price
Throws
If value is negative or invalid format
Example
const effectivePrice = EffectiveGasPrice.from(27000000000n); // 27 Gwei
const effectivePrice2 = EffectiveGasPrice.from("0x64da46800");
fromGwei()
fromGwei: (gwei) => EffectiveGasPriceType
Create EffectiveGasPrice from Gwei value
Parameters
gwei
Value in Gwei number | bigint
Returns
EffectiveGasPriceType Effective price in Wei
Example
const effectivePrice = EffectiveGasPrice.fromGwei(27n); // 27 Gwei = 27000000000 Wei
fromWei()
fromWei: (wei) => EffectiveGasPriceType
Create EffectiveGasPrice from Wei value (alias for from)
Parameters
wei
Value in Wei string | number | bigint
Returns
EffectiveGasPriceType Effective price
Example
const effectivePrice = EffectiveGasPrice.fromWei(27000000000n);
toBigInt()
toBigInt: (effectivePrice) => bigint
Parameters
effectivePrice
string | number | bigint
Returns
bigint
toGwei()
toGwei: (effectivePrice) => bigint
Parameters
effectivePrice
string | number | bigint
Returns
bigint
toNumber()
toNumber: (effectivePrice) => number
Parameters
effectivePrice
string | number | bigint
Returns
number
toWei()
toWei: (effectivePrice) => bigint
Parameters
effectivePrice
string | number | bigint
Returns
bigint

Functions

_compare()

_compare(this, other): number
Defined in: src/primitives/EffectiveGasPrice/compare.js:15 Compare two EffectiveGasPrice values

Parameters

this
EffectiveGasPriceType
other
EffectiveGasPriceType Value to compare

Returns

number -1 if this < other, 0 if equal, 1 if this > other

Example

const price1 = EffectiveGasPrice.from(27000000000n);
const price2 = EffectiveGasPrice.from(30000000000n);
EffectiveGasPrice.compare(price1, price2); // -1

_equals()

_equals(this, other): boolean
Defined in: src/primitives/EffectiveGasPrice/equals.js:15 Check if two EffectiveGasPrice values are equal

Parameters

this
EffectiveGasPriceType
other
EffectiveGasPriceType Value to compare

Returns

boolean True if equal

Example

const price1 = EffectiveGasPrice.from(27000000000n);
const price2 = EffectiveGasPrice.from(27000000000n);
EffectiveGasPrice.equals(price1, price2); // true

_toBigInt()

_toBigInt(this): bigint
Defined in: src/primitives/EffectiveGasPrice/toBigInt.js:13 Convert EffectiveGasPrice to bigint (identity function)

Parameters

this
EffectiveGasPriceType

Returns

bigint Value as bigint

Example

const effectivePrice = EffectiveGasPrice.from(27000000000n);
EffectiveGasPrice.toBigInt(effectivePrice); // 27000000000n

_toGwei()

_toGwei(this): bigint
Defined in: src/primitives/EffectiveGasPrice/toGwei.js:13 Convert EffectiveGasPrice to Gwei

Parameters

this
EffectiveGasPriceType

Returns

bigint Value in Gwei

Example

const effectivePrice = EffectiveGasPrice.from(27000000000n);
EffectiveGasPrice.toGwei(effectivePrice); // 27n Gwei

_toNumber()

_toNumber(this): number
Defined in: src/primitives/EffectiveGasPrice/toNumber.js:14 Convert EffectiveGasPrice to number WARNING: May lose precision for large values

Parameters

this
EffectiveGasPriceType

Returns

number Value as number

Example

const effectivePrice = EffectiveGasPrice.from(27000000000n);
EffectiveGasPrice.toNumber(effectivePrice); // 27000000000

_toWei()

_toWei(this): bigint
Defined in: src/primitives/EffectiveGasPrice/toWei.js:13 Convert EffectiveGasPrice to Wei (identity function)

Parameters

this
EffectiveGasPriceType

Returns

bigint Value in Wei

Example

const effectivePrice = EffectiveGasPrice.from(27000000000n);
EffectiveGasPrice.toWei(effectivePrice); // 27000000000n Wei

calculate()

calculate(baseFee, maxFee, maxPriorityFee): EffectiveGasPriceType
Defined in: src/primitives/EffectiveGasPrice/calculate.js:19 Calculate effective gas price from EIP-1559 fee parameters Formula: min(baseFee + min(maxPriorityFee, maxFee - baseFee), maxFee)

Parameters

baseFee
bigint Base fee per gas
maxFee
bigint Maximum fee per gas
maxPriorityFee
bigint Maximum priority fee per gas

Returns

EffectiveGasPriceType Effective gas price

Example

const baseFee = 25000000000n; // 25 Gwei
const maxFee = 100000000000n; // 100 Gwei
const maxPriorityFee = 2000000000n; // 2 Gwei
const effective = EffectiveGasPrice.calculate(baseFee, maxFee, maxPriorityFee);
// Returns 27000000000n (25 + 2 Gwei)

compare()

compare(effectivePrice1, effectivePrice2): number
Defined in: src/primitives/EffectiveGasPrice/index.ts:43

Parameters

effectivePrice1
string | number | bigint
effectivePrice2
string | number | bigint

Returns

number

equals()

equals(effectivePrice1, effectivePrice2): boolean
Defined in: src/primitives/EffectiveGasPrice/index.ts:36

Parameters

effectivePrice1
string | number | bigint
effectivePrice2
string | number | bigint

Returns

boolean

from()

from(value): EffectiveGasPriceType
Defined in: src/primitives/EffectiveGasPrice/from.js:16 Create EffectiveGasPrice from bigint, number, or hex string

Parameters

value
Effective price in Wei string | number | bigint

Returns

EffectiveGasPriceType Branded effective gas price

Throws

If value is negative or invalid format

Example

const effectivePrice = EffectiveGasPrice.from(27000000000n); // 27 Gwei
const effectivePrice2 = EffectiveGasPrice.from("0x64da46800");

fromGwei()

fromGwei(gwei): EffectiveGasPriceType
Defined in: src/primitives/EffectiveGasPrice/fromGwei.js:12 Create EffectiveGasPrice from Gwei value

Parameters

gwei
Value in Gwei number | bigint

Returns

EffectiveGasPriceType Effective price in Wei

Example

const effectivePrice = EffectiveGasPrice.fromGwei(27n); // 27 Gwei = 27000000000 Wei

fromWei()

fromWei(wei): EffectiveGasPriceType
Defined in: src/primitives/EffectiveGasPrice/fromWei.js:12 Create EffectiveGasPrice from Wei value (alias for from)

Parameters

wei
Value in Wei string | number | bigint

Returns

EffectiveGasPriceType Effective price

Example

const effectivePrice = EffectiveGasPrice.fromWei(27000000000n);

toBigInt()

toBigInt(effectivePrice): bigint
Defined in: src/primitives/EffectiveGasPrice/index.ts:32

Parameters

effectivePrice
string | number | bigint

Returns

bigint

toGwei()

toGwei(effectivePrice): bigint
Defined in: src/primitives/EffectiveGasPrice/index.ts:20

Parameters

effectivePrice
string | number | bigint

Returns

bigint

toNumber()

toNumber(effectivePrice): number
Defined in: src/primitives/EffectiveGasPrice/index.ts:28

Parameters

effectivePrice
string | number | bigint

Returns

number

toWei()

toWei(effectivePrice): bigint
Defined in: src/primitives/EffectiveGasPrice/index.ts:24

Parameters

effectivePrice
string | number | bigint

Returns

bigint