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

BrandedWei

Type Aliases

BrandedWei

BrandedWei = WeiType
Defined in: src/primitives/Denomination/WeiType.ts:9

WeiType

WeiType = bigint & object
Defined in: src/primitives/Denomination/WeiType.ts:6 Branded Wei type - represents Ethereum amounts in wei (smallest unit: 10^-18 ETH)

Type Declaration

[brand]
readonly [brand]: "Wei"

Variables

Wei

const Wei: object
Defined in: src/primitives/Denomination/wei-index.ts:19

Type Declaration

from()
from: (value) => WeiType
Create Wei from bigint, number, or string
Parameters
value
Value to convert (bigint, number, or string) string | number | bigint
Returns
WeiType Wei amount
See
https://voltaire.tevm.sh/primitives/denomination for Denomination documentation
Since
0.0.0
Throws
Example
const wei1 = Wei.from(1000000000n);
const wei2 = Wei.from(1000000000);
const wei3 = Wei.from("1000000000");
const wei4 = Wei.from("0x3b9aca00");
fromEther()
fromEther: (ether) => WeiType
Convert Ether to Wei Parses decimal ether string and converts to bigint wei value. Alias for Ether.toWei().
Parameters
ether
EtherType Amount in Ether (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 ether value has more than 18 decimal places
Example
const wei1 = Wei.fromEther(Ether.from("1"));     // 1000000000000000000n
const wei2 = Wei.fromEther(Ether.from("1.5"));   // 1500000000000000000n
fromGwei()
fromGwei: (gwei) => WeiType
Convert Gwei to Wei Parses decimal gwei string and converts to bigint wei value. Alias for Gwei.toWei().
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 = Wei.fromGwei(Gwei.from("5"));     // 5000000000n
const wei2 = Wei.fromGwei(Gwei.from("1.5"));   // 1500000000n
toEther()
toEther: (wei) => EtherType
Convert Wei to Ether Converts bigint wei to decimal string ether value.
Parameters
wei
WeiType Amount in Wei (bigint)
Returns
EtherType Amount in Ether (string with decimal precision)
See
https://voltaire.tevm.sh/primitives/denomination for Denomination documentation
Since
0.0.0
Throws
Example
const ether1 = Wei.toEther(Wei.from(1000000000000000000n)); // "1"
const ether2 = Wei.toEther(Wei.from(1500000000000000000n)); // "1.5"
const ether3 = Wei.toEther(Wei.from(1000000000000000n));    // "0.001"
toGwei()
toGwei: (wei) => GweiType
Convert Wei to Gwei Converts bigint wei to decimal string gwei value.
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 = Wei.toGwei(Wei.from(5000000000n)); // "5"
const gwei2 = Wei.toGwei(Wei.from(1500000000n)); // "1.5"
const gwei3 = Wei.toGwei(Wei.from(1000000n));    // "0.001"
toU256()
toU256: (wei) => Type
Convert Wei to base Uint256 type
Parameters
wei
WeiType Amount in Wei
Returns
Type Uint256 value (type cast, no conversion)
See
https://voltaire.tevm.sh/primitives/denomination for Denomination documentation
Since
0.0.0
Throws
Example
const wei = Wei.from(1000000000n);
const u256 = Wei.toU256(wei);
// u256 = 1000000000n (as Uint256)

WEI_PER_ETHER

const WEI_PER_ETHER: 1000000000000000000n = 1_000_000_000_000_000_000n
Defined in: src/primitives/Denomination/wei-constants.ts:15 Conversion constant: Wei per Ether (10^18)

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/wei-constants.ts:7 Conversion constant: Wei per Gwei (10^9)

See

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

Since

0.0.0

Functions

from()

from(value): WeiType
Defined in: src/primitives/Denomination/wei-from.ts:20 Create Wei from bigint, number, or string

Parameters

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

Returns

WeiType Wei amount

See

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

Since

0.0.0

Throws

Example

const wei1 = Wei.from(1000000000n);
const wei2 = Wei.from(1000000000);
const wei3 = Wei.from("1000000000");
const wei4 = Wei.from("0x3b9aca00");

fromEther()

fromEther(ether): WeiType
Defined in: src/primitives/Denomination/wei-fromEther.ts:22 Convert Ether to Wei Parses decimal ether string and converts to bigint wei value. Alias for Ether.toWei().

Parameters

ether
EtherType Amount in Ether (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 ether value has more than 18 decimal places

Example

const wei1 = Wei.fromEther(Ether.from("1"));     // 1000000000000000000n
const wei2 = Wei.fromEther(Ether.from("1.5"));   // 1500000000000000000n

fromGwei()

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

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 = Wei.fromGwei(Gwei.from("5"));     // 5000000000n
const wei2 = Wei.fromGwei(Gwei.from("1.5"));   // 1500000000n

toEther()

toEther(wei): EtherType
Defined in: src/primitives/Denomination/wei-toEther.ts:23 Convert Wei to Ether Converts bigint wei to decimal string ether value.

Parameters

wei
WeiType Amount in Wei (bigint)

Returns

EtherType Amount in Ether (string with decimal precision)

See

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

Since

0.0.0

Throws

Example

const ether1 = Wei.toEther(Wei.from(1000000000000000000n)); // "1"
const ether2 = Wei.toEther(Wei.from(1500000000000000000n)); // "1.5"
const ether3 = Wei.toEther(Wei.from(1000000000000000n));    // "0.001"

toGwei()

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

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 = Wei.toGwei(Wei.from(5000000000n)); // "5"
const gwei2 = Wei.toGwei(Wei.from(1500000000n)); // "1.5"
const gwei3 = Wei.toGwei(Wei.from(1000000n));    // "0.001"

toU256()

toU256(wei): Type
Defined in: src/primitives/Denomination/wei-toU256.ts:19 Convert Wei to base Uint256 type

Parameters

wei
WeiType Amount in Wei

Returns

Type Uint256 value (type cast, no conversion)

See

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

Since

0.0.0

Throws

Example

const wei = Wei.from(1000000000n);
const u256 = Wei.toU256(wei);
// u256 = 1000000000n (as Uint256)