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

primitives/GasUsed

Type Aliases

GasUsedType

GasUsedType = bigint & object
Defined in: src/primitives/GasUsed/GasUsedType.ts:8 Branded GasUsed type - actual gas consumed by transaction Found in transaction receipts (receipt.gasUsed) Range: 21000 (minimum transfer) to block gas limit (30M typical)

Type Declaration

[brand]
readonly [brand]: "GasUsed"

Variables

GasUsed

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

Type Declaration

calculateCost()
calculateCost: (gasUsed, gasPrice) => bigint
Parameters
gasUsed
string | number | bigint
gasPrice
bigint
Returns
bigint
compare()
compare: (value1, value2) => number
Parameters
value1
string | number | bigint
value2
string | number | bigint
Returns
number
equals()
equals: (value1, value2) => boolean
Parameters
value1
string | number | bigint
value2
string | number | bigint
Returns
boolean
from()
from: (value) => GasUsedType
Create GasUsed from number, bigint, or string
Parameters
value
Gas used value string | number | bigint
Returns
GasUsedType Branded gas used
Throws
If value is negative
Example
const gasUsed = GasUsed.from(51234n);
const fromReceipt = GasUsed.from(receipt.gasUsed);
toBigInt()
toBigInt: (value) => bigint
Parameters
value
string | number | bigint
Returns
bigint
toHex()
toHex: (value) => string
Parameters
value
string | number | bigint
Returns
string
toNumber()
toNumber: (value) => number
Parameters
value
string | number | bigint
Returns
number

Functions

_calculateCost()

_calculateCost(this, gasPrice): bigint
Defined in: src/primitives/GasUsed/calculateCost.js:15 Calculate transaction cost in Wei (gasUsed * gasPrice)

Parameters

this
GasUsedType
gasPrice
bigint Gas price in Wei

Returns

bigint Transaction cost in Wei

Example

const gasUsed = GasUsed.from(51234n);
const gasPrice = 20_000_000_000n; // 20 gwei
GasUsed._calculateCost.call(gasUsed, gasPrice); // 1024680000000000n Wei

_compare()

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

Parameters

this
GasUsedType
other
GasUsedType Other gas used value

Returns

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

Example

const a = GasUsed.from(21000n);
const b = GasUsed.from(51234n);
GasUsed._compare.call(a, b); // -1

_equals()

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

Parameters

this
GasUsedType
other
GasUsedType Other gas used value

Returns

boolean True if equal

Example

const a = GasUsed.from(51234n);
const b = GasUsed.from(51234n);
GasUsed._equals.call(a, b); // true

_toBigInt()

_toBigInt(this): bigint
Defined in: src/primitives/GasUsed/toBigInt.js:13 Convert GasUsed to bigint (identity, for compatibility)

Parameters

this
GasUsedType

Returns

bigint Gas used as bigint

Example

const gasUsed = GasUsed.from(51234n);
GasUsed.toBigInt(gasUsed); // 51234n

_toHex()

_toHex(this): string
Defined in: src/primitives/GasUsed/toHex.js:13 Convert GasUsed to hex string

Parameters

this
GasUsedType

Returns

string Gas used as hex string (0x prefixed)

Example

const gasUsed = GasUsed.from(51234n);
GasUsed.toHex(gasUsed); // "0xc822"

_toNumber()

_toNumber(this): number
Defined in: src/primitives/GasUsed/toNumber.js:13 Convert GasUsed to number

Parameters

this
GasUsedType

Returns

number Gas used as number

Example

const gasUsed = GasUsed.from(51234n);
GasUsed.toNumber(gasUsed); // 51234

calculateCost()

calculateCost(gasUsed, gasPrice): bigint
Defined in: src/primitives/GasUsed/index.ts:43

Parameters

gasUsed
string | number | bigint
gasPrice
bigint

Returns

bigint

compare()

compare(value1, value2): number
Defined in: src/primitives/GasUsed/index.ts:36

Parameters

value1
string | number | bigint
value2
string | number | bigint

Returns

number

equals()

equals(value1, value2): boolean
Defined in: src/primitives/GasUsed/index.ts:29

Parameters

value1
string | number | bigint
value2
string | number | bigint

Returns

boolean

from()

from(value): GasUsedType
Defined in: src/primitives/GasUsed/from.js:16 Create GasUsed from number, bigint, or string

Parameters

value
Gas used value string | number | bigint

Returns

GasUsedType Branded gas used

Throws

If value is negative

Example

const gasUsed = GasUsed.from(51234n);
const fromReceipt = GasUsed.from(receipt.gasUsed);

toBigInt()

toBigInt(value): bigint
Defined in: src/primitives/GasUsed/index.ts:21

Parameters

value
string | number | bigint

Returns

bigint

toHex()

toHex(value): string
Defined in: src/primitives/GasUsed/index.ts:25

Parameters

value
string | number | bigint

Returns

string

toNumber()

toNumber(value): number
Defined in: src/primitives/GasUsed/index.ts:17

Parameters

value
string | number | bigint

Returns

number