Skip to main content
@tevm/voltaire
@tevm/voltaire / index / BrandedGwei

BrandedGwei

Type Aliases

BrandedGwei

BrandedGwei = GweiType
Defined in: src/primitives/Denomination/GweiType.ts:12

GweiType

GweiType = string & object
Defined in: src/primitives/Denomination/GweiType.ts:9 Branded Gwei type - represents Ethereum amounts in gwei (10^9 wei = 10^-9 ETH) Uses string to support decimal values like “1.5” or “0.001” For whole number wei amounts, use WeiType (bigint)

Type Declaration

[brand]
readonly [brand]: "Gwei"

Variables

Gwei

const Gwei: object
Defined in: src/primitives/Denomination/gwei-index.ts:19

Type Declaration

from()
from: (value) => GweiType
Create Gwei from bigint, number, or string Gwei is a string type to support decimal values like “1.5” or “0.001”
Parameters
value
Value to convert (bigint, number, or string) string | number | bigint
Returns
GweiType Gwei amount as branded string
See
https://voltaire.tevm.sh/primitives/denomination for Denomination documentation
Since
0.0.0
Throws
If value is not a valid number
Example
const gwei1 = Gwei.from(1n);        // "1"
const gwei2 = Gwei.from(1.5);       // "1.5"
const gwei3 = Gwei.from("1.5");     // "1.5"
const gwei4 = Gwei.from("0.001");   // "0.001"
fromEther()
fromEther: (ether) => GweiType
Convert Ether to Gwei Converts ether string to gwei string (multiplies by 10^9). Alias for Ether.toGwei().
Parameters
ether
EtherType Amount in Ether (string)
Returns
GweiType Amount in Gwei (string)
See
https://voltaire.tevm.sh/primitives/denomination for Denomination documentation
Since
0.0.0
Throws
Example
const gwei1 = Gwei.fromEther(Ether.from("1"));   // "1000000000"
const gwei2 = Gwei.fromEther(Ether.from("1.5")); // "1500000000"
fromWei()
fromWei: (wei) => GweiType
Convert Wei to Gwei Converts bigint wei to decimal string gwei value. Alias for Wei.toGwei().
Parameters
wei
WeiType Amount in Wei (bigint)
Returns
GweiType Amount in Gwei (string with decimal precision)
See
https://voltaire.tevm.sh/primitives/denomination for Denomination documentation
Since
0.0.0
Throws
Example
const gwei1 = Gwei.fromWei(Wei.from(5000000000n)); // "5"
const gwei2 = Gwei.fromWei(Wei.from(1500000000n)); // "1.5"
toEther()
toEther: (gwei) => EtherType
Convert Gwei to Ether Converts gwei string to ether string (divides by 10^9).
Parameters
gwei
GweiType Amount in Gwei (string)
Returns
EtherType Amount in Ether (string)
See
https://voltaire.tevm.sh/primitives/denomination for Denomination documentation
Since
0.0.0
Throws
Example
const ether1 = Gwei.toEther(Gwei.from("1000000000")); // "1"
const ether2 = Gwei.toEther(Gwei.from("1500000000")); // "1.5"
const ether3 = Gwei.toEther(Gwei.from("1"));          // "0.000000001"
toU256()
toU256: (gwei) => Type
Convert Gwei to Uint256 (in Wei) Converts gwei string to wei bigint, then returns as Uint256.
Parameters
gwei
GweiType Amount in Gwei (string)
Returns
Type Uint256 value in Wei
See
https://voltaire.tevm.sh/primitives/denomination for Denomination documentation
Since
0.0.0
Throws
If gwei value has more than 9 decimal places
Example
const u256_1 = Gwei.toU256(Gwei.from("5"));   // 5000000000n
const u256_2 = Gwei.toU256(Gwei.from("1.5")); // 1500000000n
toWei()
toWei: (gwei) => WeiType
Convert Gwei to Wei Parses decimal gwei string and converts to bigint wei value.
Parameters
gwei
GweiType Amount in Gwei (string, supports decimals like “1.5”)
Returns
WeiType Amount in Wei (bigint)
See
https://voltaire.tevm.sh/primitives/denomination for Denomination documentation
Since
0.0.0
Throws
If gwei value has more than 9 decimal places
Example
const wei1 = Gwei.toWei(Gwei.from("5"));     // 5000000000n
const wei2 = Gwei.toWei(Gwei.from("1.5"));   // 1500000000n
const wei3 = Gwei.toWei(Gwei.from("0.001")); // 1000000n

GWEI_PER_ETHER

const GWEI_PER_ETHER: 1000000000n = 1_000_000_000n
Defined in: src/primitives/Denomination/gwei-constants.ts:15 Number of Gwei in one Ether (10^9)

See

https://voltaire.tevm.sh/primitives/denomination for Denomination documentation

Since

0.0.0

WEI_PER_GWEI

const WEI_PER_GWEI: 1000000000n = 1_000_000_000n
Defined in: src/primitives/Denomination/gwei-constants.ts:7 Number of Wei in one Gwei (10^9)

See

https://voltaire.tevm.sh/primitives/denomination for Denomination documentation

Since

0.0.0

Functions

from()

from(value): GweiType
Defined in: src/primitives/Denomination/gwei-from.ts:21 Create Gwei from bigint, number, or string Gwei is a string type to support decimal values like “1.5” or “0.001”

Parameters

value
Value to convert (bigint, number, or string) string | number | bigint

Returns

GweiType Gwei amount as branded string

See

https://voltaire.tevm.sh/primitives/denomination for Denomination documentation

Since

0.0.0

Throws

If value is not a valid number

Example

const gwei1 = Gwei.from(1n);        // "1"
const gwei2 = Gwei.from(1.5);       // "1.5"
const gwei3 = Gwei.from("1.5");     // "1.5"
const gwei4 = Gwei.from("0.001");   // "0.001"

fromEther()

fromEther(ether): GweiType
Defined in: src/primitives/Denomination/gwei-fromEther.ts:22 Convert Ether to Gwei Converts ether string to gwei string (multiplies by 10^9). Alias for Ether.toGwei().

Parameters

ether
EtherType Amount in Ether (string)

Returns

GweiType Amount in Gwei (string)

See

https://voltaire.tevm.sh/primitives/denomination for Denomination documentation

Since

0.0.0

Throws

Example

const gwei1 = Gwei.fromEther(Ether.from("1"));   // "1000000000"
const gwei2 = Gwei.fromEther(Ether.from("1.5")); // "1500000000"

fromWei()

fromWei(wei): GweiType
Defined in: src/primitives/Denomination/gwei-fromWei.ts:22 Convert Wei to Gwei Converts bigint wei to decimal string gwei value. Alias for Wei.toGwei().

Parameters

wei
WeiType Amount in Wei (bigint)

Returns

GweiType Amount in Gwei (string with decimal precision)

See

https://voltaire.tevm.sh/primitives/denomination for Denomination documentation

Since

0.0.0

Throws

Example

const gwei1 = Gwei.fromWei(Wei.from(5000000000n)); // "5"
const gwei2 = Gwei.fromWei(Wei.from(1500000000n)); // "1.5"

toEther()

toEther(gwei): EtherType
Defined in: src/primitives/Denomination/gwei-toEther.ts:23 Convert Gwei to Ether Converts gwei string to ether string (divides by 10^9).

Parameters

gwei
GweiType Amount in Gwei (string)

Returns

EtherType Amount in Ether (string)

See

https://voltaire.tevm.sh/primitives/denomination for Denomination documentation

Since

0.0.0

Throws

Example

const ether1 = Gwei.toEther(Gwei.from("1000000000")); // "1"
const ether2 = Gwei.toEther(Gwei.from("1500000000")); // "1.5"
const ether3 = Gwei.toEther(Gwei.from("1"));          // "0.000000001"

toU256()

toU256(gwei): Type
Defined in: src/primitives/Denomination/gwei-toU256.ts:21 Convert Gwei to Uint256 (in Wei) Converts gwei string to wei bigint, then returns as Uint256.

Parameters

gwei
GweiType Amount in Gwei (string)

Returns

Type Uint256 value in Wei

See

https://voltaire.tevm.sh/primitives/denomination for Denomination documentation

Since

0.0.0

Throws

If gwei value has more than 9 decimal places

Example

const u256_1 = Gwei.toU256(Gwei.from("5"));   // 5000000000n
const u256_2 = Gwei.toU256(Gwei.from("1.5")); // 1500000000n

toWei()

toWei(gwei): WeiType
Defined in: src/primitives/Denomination/gwei-toWei.ts:23 Convert Gwei to Wei Parses decimal gwei string and converts to bigint wei value.

Parameters

gwei
GweiType Amount in Gwei (string, supports decimals like “1.5”)

Returns

WeiType Amount in Wei (bigint)

See

https://voltaire.tevm.sh/primitives/denomination for Denomination documentation

Since

0.0.0

Throws

If gwei value has more than 9 decimal places

Example

const wei1 = Gwei.toWei(Gwei.from("5"));     // 5000000000n
const wei2 = Gwei.toWei(Gwei.from("1.5"));   // 1500000000n
const wei3 = Gwei.toWei(Gwei.from("0.001")); // 1000000n