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

primitives/Uint

Interfaces

UintConstructor()

Defined in: src/primitives/Uint/UintConstructor.ts:69
UintConstructor(value): Type
Defined in: src/primitives/Uint/UintConstructor.ts:70

Parameters

value
string | number | bigint

Returns

Type

Properties

bitLength()
bitLength: (uint) => number
Defined in: src/primitives/Uint/UintConstructor.ts:112 Get number of bits required to represent value
Parameters
uint
Type Value to check
Returns
number Number of bits (0-256)
Example
const a = Uint(255n);
const bits1 = Uint.bitLength(a); // 8
const bits2 = a.bitLength(); // 8
bitwiseAnd()
bitwiseAnd: (uint, b) => Type
Defined in: src/primitives/Uint/UintConstructor.ts:97 Bitwise AND
Parameters
uint
Type First operand
b
Type Second operand
Returns
Type uint & b
Example
const a = Uint(0xffn);
const b = Uint(0x0fn);
const result1 = Uint.bitwiseAnd(a, b); // 0x0f
const result2 = a.bitwiseAnd(b); // 0x0f
bitwiseNot()
bitwiseNot: (uint) => Type
Defined in: src/primitives/Uint/UintConstructor.ts:100 Bitwise NOT
Parameters
uint
Type Operand
Returns
Type ~uint & MAX
Example
const a = Uint(0n);
const result1 = Uint.bitwiseNot(a); // MAX
const result2 = a.bitwiseNot(); // MAX
bitwiseOr()
bitwiseOr: (uint, b) => Type
Defined in: src/primitives/Uint/UintConstructor.ts:98 Bitwise OR
Parameters
uint
Type First operand
b
Type Second operand
Returns
Type uint | b
Example
const a = Uint(0xf0n);
const b = Uint(0x0fn);
const result1 = Uint.bitwiseOr(a, b); // 0xff
const result2 = a.bitwiseOr(b); // 0xff
bitwiseXor()
bitwiseXor: (uint, b) => Type
Defined in: src/primitives/Uint/UintConstructor.ts:99 Bitwise XOR
Parameters
uint
Type First operand
b
Type Second operand
Returns
Type uint ^ b
Example
const a = Uint(0xffn);
const b = Uint(0x0fn);
const result1 = Uint.bitwiseXor(a, b); // 0xf0
const result2 = a.bitwiseXor(b); // 0xf0
dividedBy()
dividedBy: (uint, b) => Type
Defined in: src/primitives/Uint/UintConstructor.ts:94 Divide Uint256 value
Parameters
uint
Type Dividend
b
Type Divisor
Returns
Type Quotient (uint / b), floor division
Throws
Error if divisor is zero
Example
const a = Uint(100n);
const b = Uint(10n);
const quotient1 = Uint.dividedBy(a, b); // 10
const quotient2 = a.dividedBy(b); // 10
equals()
equals: (uint, b) => boolean
Defined in: src/primitives/Uint/UintConstructor.ts:103 Check equality
Parameters
uint
Type First value
b
Type Second value
Returns
boolean true if uint === b
Example
const a = Uint(100n);
const b = Uint(100n);
const eq1 = Uint.equals(a, b); // true
const eq2 = a.equals(b); // true
greaterThan()
greaterThan: (uint, b) => boolean
Defined in: src/primitives/Uint/UintConstructor.ts:107 Check greater than
Parameters
uint
Type First value
b
Type Second value
Returns
boolean true if uint > b
Example
const a = Uint(200n);
const b = Uint(100n);
const isGreater1 = Uint.greaterThan(a, b); // true
const isGreater2 = a.greaterThan(b); // true
greaterThanOrEqual()
greaterThanOrEqual: (uint, b) => boolean
Defined in: src/primitives/Uint/UintConstructor.ts:108 Check greater than or equal
Parameters
uint
Type First value
b
Type Second value
Returns
boolean true if uint >= b
Example
const a = Uint(100n);
const b = Uint(100n);
const isGte1 = Uint.greaterThanOrEqual(a, b); // true
const isGte2 = a.greaterThanOrEqual(b); // true
isValid()
isValid: (value) => value is Type
Defined in: src/primitives/Uint/UintConstructor.ts:84 Check if value is a valid Uint256
Parameters
value
unknown Value to check
Returns
value is Type true if value is valid Uint256
Example
const isValid = Uint.isValid(100n); // true
const isInvalid = Uint.isValid(-1n); // false
isZero()
isZero: (uint) => boolean
Defined in: src/primitives/Uint/UintConstructor.ts:109 Check if value is zero
Parameters
uint
Type Value to check
Returns
boolean true if uint === 0
Example
const a = Uint(0n);
const isZero1 = Uint.isZero(a); // true
const isZero2 = a.isZero(); // true
leadingZeros()
leadingZeros: (uint) => number
Defined in: src/primitives/Uint/UintConstructor.ts:113 Get number of leading zero bits
Parameters
uint
Type Value to check
Returns
number Number of leading zeros (0-256)
Example
const a = Uint(1n);
const zeros1 = Uint.leadingZeros(a); // 255
const zeros2 = a.leadingZeros(); // 255
lessThan()
lessThan: (uint, b) => boolean
Defined in: src/primitives/Uint/UintConstructor.ts:105 Check less than
Parameters
uint
Type First value
b
Type Second value
Returns
boolean true if uint < b
Example
const a = Uint(100n);
const b = Uint(200n);
const isLess1 = Uint.lessThan(a, b); // true
const isLess2 = a.lessThan(b); // true
lessThanOrEqual()
lessThanOrEqual: (uint, b) => boolean
Defined in: src/primitives/Uint/UintConstructor.ts:106 Check less than or equal
Parameters
uint
Type First value
b
Type Second value
Returns
boolean true if uint is less than or equal to b
Example
const a = Uint(100n);
const b = Uint(100n);
const isLte1 = Uint.lessThanOrEqual(a, b); // true
const isLte2 = a.lessThanOrEqual(b); // true
MAX
MAX: Type
Defined in: src/primitives/Uint/UintConstructor.ts:72
maximum()
maximum: (uint, b) => Type
Defined in: src/primitives/Uint/UintConstructor.ts:111 Get maximum of two values
Parameters
uint
Type First value
b
Type Second value
Returns
Type max(uint, b)
Example
const a = Uint(100n);
const b = Uint(200n);
const max1 = Uint.maximum(a, b); // 200
const max2 = a.maximum(b); // 200
MIN
MIN: Type
Defined in: src/primitives/Uint/UintConstructor.ts:73
minimum()
minimum: (uint, b) => Type
Defined in: src/primitives/Uint/UintConstructor.ts:110 Get minimum of two values
Parameters
uint
Type First value
b
Type Second value
Returns
Type min(uint, b)
Example
const a = Uint(100n);
const b = Uint(200n);
const min1 = Uint.minimum(a, b); // 100
const min2 = a.minimum(b); // 100
minus()
minus: (uint, b) => Type
Defined in: src/primitives/Uint/UintConstructor.ts:92 Subtract Uint256 value with wrapping
Parameters
uint
Type First operand
b
Type Second operand
Returns
Type Difference (uint - b) mod 2^256
Example
const a = Uint(100n);
const b = Uint(50n);
const diff1 = Uint.minus(a, b); // 50
const diff2 = a.minus(b); // 50
modulo()
modulo: (uint, b) => Type
Defined in: src/primitives/Uint/UintConstructor.ts:95 Modulo operation
Parameters
uint
Type Dividend
b
Type Divisor
Returns
Type Remainder (uint % b)
Throws
Error if divisor is zero
Example
const a = Uint(100n);
const b = Uint(30n);
const remainder1 = Uint.modulo(a, b); // 10
const remainder2 = a.modulo(b); // 10
notEquals()
notEquals: (uint, b) => boolean
Defined in: src/primitives/Uint/UintConstructor.ts:104 Check inequality
Parameters
uint
Type First value
b
Type Second value
Returns
boolean true if uint !== b
Example
const a = Uint(100n);
const b = Uint(200n);
const isNotEq1 = Uint.notEquals(a, b); // true
const isNotEq2 = a.notEquals(b); // true
ONE
ONE: Type
Defined in: src/primitives/Uint/UintConstructor.ts:75
plus()
plus: (uint, b) => Type
Defined in: src/primitives/Uint/UintConstructor.ts:91 Add Uint256 value with wrapping
Parameters
uint
Type First operand
b
Type Second operand
Returns
Type Sum (uint + b) mod 2^256
Example
const a = Uint(100n);
const b = Uint(50n);
const sum1 = Uint.plus(a, b); // 150
const sum2 = a.plus(b); // 150
popCount()
popCount: (uint) => number
Defined in: src/primitives/Uint/UintConstructor.ts:114 Count number of set bits (population count)
Parameters
uint
Type Value to check
Returns
number Number of 1 bits
Example
const a = Uint(0xffn);
const count1 = Uint.popCount(a); // 8
const count2 = a.popCount(); // 8
prototype
prototype: UintPrototype
Defined in: src/primitives/Uint/UintConstructor.ts:71
shiftLeft()
shiftLeft: (uint, bits) => Type
Defined in: src/primitives/Uint/UintConstructor.ts:101 Left shift
Parameters
uint
Type Value to shift
bits
Type Number of bits to shift
Returns
Type uint shifted left by bits (mod 2^256)
Example
const a = Uint(1n);
const b = Uint(8n);
const result1 = Uint.shiftLeft(a, b); // 256
const result2 = a.shiftLeft(b); // 256
shiftRight()
shiftRight: (uint, bits) => Type
Defined in: src/primitives/Uint/UintConstructor.ts:102 Right shift
Parameters
uint
Type Value to shift
bits
Type Number of bits to shift
Returns
Type uint shifted right by bits
Example
const a = Uint(256n);
const b = Uint(8n);
const result1 = Uint.shiftRight(a, b); // 1
const result2 = a.shiftRight(b); // 1
SIZE
SIZE: number
Defined in: src/primitives/Uint/UintConstructor.ts:76
times()
times: (uint, b) => Type
Defined in: src/primitives/Uint/UintConstructor.ts:93 Multiply Uint256 value with wrapping
Parameters
uint
Type First operand
b
Type Second operand
Returns
Type Product (uint * b) mod 2^256
Example
const a = Uint(10n);
const b = Uint(5n);
const product1 = Uint.times(a, b); // 50
const product2 = a.times(b); // 50
toAbiEncoded()
toAbiEncoded: (uint) => Uint8Array
Defined in: src/primitives/Uint/UintConstructor.ts:89 Convert Uint256 to ABI-encoded bytes (32 bytes, big-endian) This is identical to toBytes() - all Uint256 values in ABI encoding are represented as 32-byte big-endian values.
Parameters
uint
Type Uint256 value to encode
Returns
Uint8Array 32-byte ABI-encoded Uint8Array
Example
const value = Uint(255n);
const encoded1 = Uint.toAbiEncoded(value);
const encoded2 = value.toAbiEncoded();
toBigInt()
toBigInt: (uint) => bigint
Defined in: src/primitives/Uint/UintConstructor.ts:86 Convert Uint256 to bigint
Parameters
uint
Type Uint256 value to convert
Returns
bigint bigint value
Example
const value = Uint(255n);
const bigint1 = Uint.toBigInt(value);
const bigint2 = value.toBigInt();
toBytes()
toBytes: (uint) => Uint8Array
Defined in: src/primitives/Uint/UintConstructor.ts:88 Convert Uint256 to bytes (big-endian, 32 bytes)
Parameters
uint
Type Uint256 value to convert
Returns
Uint8Array 32-byte Uint8Array
Example
const value = Uint(255n);
const bytes1 = Uint.toBytes(value);
const bytes2 = value.toBytes();
toHex()
toHex: (uint, padded) => string
Defined in: src/primitives/Uint/UintConstructor.ts:85 Convert Uint256 to hex string
Parameters
uint
Type Uint256 value to convert
padded
boolean = true Whether to pad to 64 characters (32 bytes)
Returns
string Hex string with 0x prefix
Example
const value = Uint(255n);
const hex1 = Uint.toHex(value); // "0x00...ff"
const hex2 = value.toHex(); // "0x00...ff"
const hex3 = value.toHex(false); // "0xff"
toNumber()
toNumber: (uint) => number
Defined in: src/primitives/Uint/UintConstructor.ts:87 Convert Uint256 to number
Parameters
uint
Type Uint256 value to convert
Returns
number number value
Throws
Error if value exceeds MAX_SAFE_INTEGER
Example
const value = Uint(255n);
const num1 = Uint.toNumber(value);
const num2 = value.toNumber();
toPower()
toPower: (uint, exponent) => Type
Defined in: src/primitives/Uint/UintConstructor.ts:96 Exponentiation
Parameters
uint
Type Base value
exponent
Type Exponent value
Returns
Type uint^exponent mod 2^256
Example
const base = Uint(2n);
const exp = Uint(8n);
const result1 = Uint.toPower(base, exp); // 256
const result2 = base.toPower(exp); // 256
toString()
toString: (uint, radix) => string
Defined in: src/primitives/Uint/UintConstructor.ts:90 Convert Uint256 to string representation
Parameters
uint
Type Uint256 value to convert
radix
number = 10 Base for string conversion (2, 10, 16, etc.)
Returns
string String representation
Example
const value = Uint(255n);
const dec1 = Uint.toString(value, 10); // "255"
const dec2 = value.toString(10); // "255"
const hex = value.toString(16); // "ff"
tryFrom()
tryFrom: (value) => Type | undefined
Defined in: src/primitives/Uint/UintConstructor.ts:83 Try to create Uint256, returns undefined if invalid (standard form)
Parameters
value
bigint, number, or string string | number | bigint
Returns
Type | undefined Uint256 value or undefined
Example
const a = Uint.tryFrom(100n); // Uint256
const b = Uint.tryFrom(-1n); // undefined
const c = Uint.tryFrom("invalid"); // undefined
ZERO
ZERO: Type
Defined in: src/primitives/Uint/UintConstructor.ts:74

Methods

from()
from(value): Type
Defined in: src/primitives/Uint/UintConstructor.ts:77
Parameters
value
string | number | bigint
Returns
Type
fromAbiEncoded()
fromAbiEncoded(value): Type
Defined in: src/primitives/Uint/UintConstructor.ts:82
Parameters
value
Uint8Array
Returns
Type
fromBigInt()
fromBigInt(value): Type
Defined in: src/primitives/Uint/UintConstructor.ts:79
Parameters
value
bigint
Returns
Type
fromBytes()
fromBytes(value): Type
Defined in: src/primitives/Uint/UintConstructor.ts:81
Parameters
value
Uint8Array
Returns
Type
fromHex()
fromHex(value): Type
Defined in: src/primitives/Uint/UintConstructor.ts:78
Parameters
value
string
Returns
Type
fromNumber()
fromNumber(value): Type
Defined in: src/primitives/Uint/UintConstructor.ts:80
Parameters
value
number | bigint
Returns
Type

Type Aliases

BrandedUint

BrandedUint = Type
Defined in: src/primitives/Uint/Uint256Type.ts:19

Deprecated

Use Uint256Type instead

BrandedUint256

BrandedUint256 = Type
Defined in: src/primitives/Uint/Uint256Type.ts:14

Deprecated

Use Uint256Type instead

Type

Type = bigint & object
Defined in: src/primitives/Uint/Uint256Type.ts:9 Uint256 type

Type Declaration

[brand]
readonly [brand]: "Uint256"

See

https://voltaire.tevm.sh/primitives/uint256 for Uint256 documentation

Since

0.0.0

Variables

MAX

const MAX: Type
Defined in: src/primitives/Uint/constants.ts:17 Maximum Uint256 value: 2^256 - 1

See

https://voltaire.tevm.sh/primitives/uint for Uint documentation

Since

0.0.0

MIN

const MIN: Type
Defined in: src/primitives/Uint/constants.ts:25 Minimum Uint256 value: 0

See

https://voltaire.tevm.sh/primitives/uint for Uint documentation

Since

0.0.0

ONE

const ONE: Type
Defined in: src/primitives/Uint/constants.ts:41 One value

See

https://voltaire.tevm.sh/primitives/uint for Uint documentation

Since

0.0.0

SIZE

const SIZE: 32 = 32
Defined in: src/primitives/Uint/constants.ts:9 Size in bytes (32 bytes for Uint256)

See

https://voltaire.tevm.sh/primitives/uint for Uint documentation

Since

0.0.0

Uint256Type

const Uint256Type: object
Defined in: src/primitives/Uint/index.ts:105

Type Declaration

bitLength()
bitLength: (uint) => number
Parameters
uint
Type
Returns
number
bitwiseAnd()
bitwiseAnd: (uint, b) => Type
Parameters
uint
Type
b
Type
Returns
Type
bitwiseNot()
bitwiseNot: (uint) => Type
Parameters
uint
Type
Returns
Type
bitwiseOr()
bitwiseOr: (uint, b) => Type
Parameters
uint
Type
b
Type
Returns
Type
bitwiseXor()
bitwiseXor: (uint, b) => Type
Parameters
uint
Type
b
Type
Returns
Type
clone()
clone: (uint) => Type
Parameters
uint
Type
Returns
Type
dividedBy()
dividedBy: (uint, b) => Type
Parameters
uint
Type
b
Type
Returns
Type
equals()
equals: (uint, b) => boolean
Parameters
uint
Type
b
Type
Returns
boolean
from()
from: (value) => Type
Parameters
value
bigint | number | string
Returns
Type
fromAbiEncoded()
fromAbiEncoded: (data) => Type
Parameters
data
Uint8Array
Returns
Type
fromBigInt()
fromBigInt: (value) => Type
Parameters
value
bigint
Returns
Type
fromBytes()
fromBytes: (bytes) => Type
Parameters
bytes
Uint8Array
Returns
Type
fromHex()
fromHex: (hex) => Type
Parameters
hex
string
Returns
Type
fromNumber()
fromNumber: (value) => Type
Parameters
value
number
Returns
Type
gcd()
gcd: (a, b) => Type
Parameters
a
Type
b
Type
Returns
Type
greaterThan()
greaterThan: (uint, b) => boolean
Parameters
uint
Type
b
Type
Returns
boolean
greaterThanOrEqual()
greaterThanOrEqual: (uint, b) => boolean
Parameters
uint
Type
b
Type
Returns
boolean
isPowerOf2()
isPowerOf2: (uint) => boolean
Parameters
uint
Type
Returns
boolean
isValid()
isValid: (value) => value is Type
Parameters
value
unknown
Returns
value is Type
isZero()
isZero: (uint) => boolean
Parameters
uint
Type
Returns
boolean
lcm()
lcm: (a, b) => Type
Parameters
a
Type
b
Type
Returns
Type
leadingZeros()
leadingZeros: (uint) => number
Parameters
uint
Type
Returns
number
lessThan()
lessThan: (uint, b) => boolean
Parameters
uint
Type
b
Type
Returns
boolean
lessThanOrEqual()
lessThanOrEqual: (uint, b) => boolean
Parameters
uint
Type
b
Type
Returns
boolean
max()
max: (…values) => Type
Parameters
values
Type[]
Returns
Type
MAX
MAX: Type
maximum()
maximum: (uint, b) => Type
Parameters
uint
Type
b
Type
Returns
Type
min()
min: (…values) => Type
Parameters
values
Type[]
Returns
Type
MIN
MIN: Type
minimum()
minimum: (uint, b) => Type
Parameters
uint
Type
b
Type
Returns
Type
minus()
minus: (uint, b) => Type
Parameters
uint
Type
b
Type
Returns
Type
modulo()
modulo: (uint, b) => Type
Parameters
uint
Type
b
Type
Returns
Type
notEquals()
notEquals: (uint, b) => boolean
Parameters
uint
Type
b
Type
Returns
boolean
ONE
ONE: Type
plus()
plus: (uint, b) => Type
Parameters
uint
Type
b
Type
Returns
Type
popCount()
popCount: (uint) => number
Parameters
uint
Type
Returns
number
product()
product: (…values) => Type
Parameters
values
Type[]
Returns
Type
shiftLeft()
shiftLeft: (uint, bits) => Type
Parameters
uint
Type
bits
Type
Returns
Type
shiftRight()
shiftRight: (uint, bits) => Type
Parameters
uint
Type
bits
Type
Returns
Type
SIZE
SIZE: 32
sum()
sum: (…values) => Type
Parameters
values
Type[]
Returns
Type
times()
times: (uint, b) => Type
Parameters
uint
Type
b
Type
Returns
Type
toAbiEncoded()
toAbiEncoded: (uint) => Uint8Array
Parameters
uint
Type
Returns
Uint8Array
toBigInt()
toBigInt: (uint) => bigint
Parameters
uint
Type
Returns
bigint
toBytes()
toBytes: (uint, size?) => Uint8Array
Parameters
uint
Type
size?
number
Returns
Uint8Array
toHex()
toHex: (uint, padded?) => string
Parameters
uint
Type
padded?
boolean
Returns
string
toNumber()
toNumber: (uint) => number
Parameters
uint
Type
Returns
number
toPower()
toPower: (uint, exponent) => Type
Parameters
uint
Type
exponent
Type
Returns
Type
toString()
toString: (uint, radix?) => string
Parameters
uint
Type
radix?
number
Returns
string
tryFrom()
tryFrom: (value) => Type | undefined
Parameters
value
bigint | number | string
Returns
Type | undefined
ZERO
ZERO: Type

ZERO

const ZERO: Type
Defined in: src/primitives/Uint/constants.ts:33 Zero value

See

https://voltaire.tevm.sh/primitives/uint for Uint documentation

Since

0.0.0

Functions

bitLength()

bitLength(uint): number
Defined in: src/primitives/Uint/bitLength.ts:16 Get number of bits required to represent value

Parameters

uint
Type Value to check

Returns

number Number of bits (0-256)

Example

const a = Uint(255n);
const bits1 = Uint.bitLength(a); // 8
const bits2 = a.bitLength(); // 8

bitwiseAnd()

bitwiseAnd(uint, b): Type
Defined in: src/primitives/Uint/bitwiseAnd.ts:18 Bitwise AND

Parameters

uint
Type First operand
b
Type Second operand

Returns

Type uint & b

Example

const a = Uint(0xffn);
const b = Uint(0x0fn);
const result1 = Uint.bitwiseAnd(a, b); // 0x0f
const result2 = a.bitwiseAnd(b); // 0x0f

bitwiseNot()

bitwiseNot(uint): Type
Defined in: src/primitives/Uint/bitwiseNot.ts:17 Bitwise NOT

Parameters

uint
Type Operand

Returns

Type ~uint & MAX

Example

const a = Uint(0n);
const result1 = Uint.bitwiseNot(a); // MAX
const result2 = a.bitwiseNot(); // MAX

bitwiseOr()

bitwiseOr(uint, b): Type
Defined in: src/primitives/Uint/bitwiseOr.ts:18 Bitwise OR

Parameters

uint
Type First operand
b
Type Second operand

Returns

Type uint | b

Example

const a = Uint(0xf0n);
const b = Uint(0x0fn);
const result1 = Uint.bitwiseOr(a, b); // 0xff
const result2 = a.bitwiseOr(b); // 0xff

bitwiseXor()

bitwiseXor(uint, b): Type
Defined in: src/primitives/Uint/bitwiseXor.ts:18 Bitwise XOR

Parameters

uint
Type First operand
b
Type Second operand

Returns

Type uint ^ b

Example

const a = Uint(0xffn);
const b = Uint(0x0fn);
const result1 = Uint.bitwiseXor(a, b); // 0xf0
const result2 = a.bitwiseXor(b); // 0xf0

clone()

clone(uint): Type
Defined in: src/primitives/Uint/clone.js:17 Create a copy of a Uint256 value

Parameters

uint
Type Uint256 value to clone

Returns

Type Copy of the value

See

https://voltaire.tevm.sh/primitives/uint for Uint documentation

Since

0.0.0

Throws

Example

import * as Uint256 from './primitives/Uint/index.js';
const n1 = Uint256.from(100n);
const n2 = Uint256.clone(n1);
console.log(Uint256.equals(n1, n2)); // true

dividedBy()

dividedBy(uint, b): Type
Defined in: src/primitives/Uint/dividedBy.ts:19 Divide Uint256 value

Parameters

uint
Type Dividend
b
Type Divisor

Returns

Type Quotient (uint / b), floor division

Throws

Error if divisor is zero

Example

const a = Uint(100n);
const b = Uint(10n);
const quotient1 = Uint.dividedBy(a, b); // 10
const quotient2 = a.dividedBy(b); // 10

equals()

equals(uint, b): boolean
Defined in: src/primitives/Uint/equals.ts:18 Check equality

Parameters

uint
Type First value
b
Type Second value

Returns

boolean true if uint === b

Example

const a = Uint(100n);
const b = Uint(100n);
const eq1 = Uint.equals(a, b); // true
const eq2 = a.equals(b); // true

from()

from(value): Type
Defined in: src/primitives/Uint/from.ts:18 Create Uint256 from bigint or string (standard form)

Parameters

value
bigint or decimal/hex string string | number | bigint

Returns

Type Uint256 value

Throws

Error if value is out of range or invalid

Example

const a = Uint.from(100n);
const b = Uint.from("255");
const c = Uint.from("0xff");

fromAbiEncoded()

fromAbiEncoded(bytes): Type
Defined in: src/primitives/Uint/fromAbiEncoded.ts:18 Decode Uint256 from ABI-encoded bytes (32 bytes, big-endian)

Parameters

bytes
Uint8Array 32-byte ABI-encoded data

Returns

Type Decoded Uint256 value

Throws

Error if bytes length is not 32

Example

const encoded = new Uint8Array(32);
encoded[31] = 255;
const value = Uint.fromAbiEncoded(encoded); // 255n

fromBigInt()

fromBigInt(value): Type
Defined in: src/primitives/Uint/fromBigInt.ts:16 Create Uint256 from bigint

Parameters

value
bigint bigint to convert

Returns

Type Uint256 value

Throws

Error if value out of range

Example

const value = Uint.fromBigInt(100n);

fromBytes()

fromBytes(bytes): Type
Defined in: src/primitives/Uint/fromBytes.ts:16 Create Uint256 from bytes (big-endian)

Parameters

bytes
Uint8Array bytes to convert

Returns

Type Uint256 value

Throws

Error if bytes length exceeds 32

Example

const bytes = new Uint8Array([0xff, 0x00]);
const value = Uint.fromBytes(bytes);

fromHex()

fromHex(hex): Type
Defined in: src/primitives/Uint/fromHex.ts:19 Create Uint256 from hex string

Parameters

hex
string Hex string to convert

Returns

Type Uint256 value

Throws

If value is negative

Throws

If value exceeds maximum

Example

const value = Uint.fromHex("0xff");
const value2 = Uint.fromHex("ff");

fromNumber()

fromNumber(value): Type
Defined in: src/primitives/Uint/fromNumber.ts:16 Create Uint256 from number

Parameters

value
number number to convert

Returns

Type Uint256 value

Throws

Error if value is not an integer or out of range

Example

const value = Uint.fromNumber(255);

gcd()

gcd(a, b): Type
Defined in: src/primitives/Uint/gcd.js:18 Calculate greatest common divisor using Euclidean algorithm

Parameters

a
Type First value
b
Type Second value

Returns

Type GCD of a and b

See

https://voltaire.tevm.sh/primitives/uint for Uint documentation

Since

0.0.0

Throws

Example

import * as Uint256 from './primitives/Uint/index.js';
const result = Uint256.gcd(Uint256.from(48n), Uint256.from(18n)); // 6n

greaterThan()

greaterThan(uint, b): boolean
Defined in: src/primitives/Uint/greaterThan.ts:18 Check greater than

Parameters

uint
Type First value
b
Type Second value

Returns

boolean true if uint > b

Example

const a = Uint(200n);
const b = Uint(100n);
const isGreater1 = Uint.greaterThan(a, b); // true
const isGreater2 = a.greaterThan(b); // true

greaterThanOrEqual()

greaterThanOrEqual(uint, b): boolean
Defined in: src/primitives/Uint/greaterThanOrEqual.ts:18 Check greater than or equal

Parameters

uint
Type First value
b
Type Second value

Returns

boolean true if uint >= b

Example

const a = Uint(100n);
const b = Uint(100n);
const isGte1 = Uint.greaterThanOrEqual(a, b); // true
const isGte2 = a.greaterThanOrEqual(b); // true

isPowerOf2()

isPowerOf2(value): boolean
Defined in: src/primitives/Uint/isPowerOf2.js:18 Check if value is a power of 2

Parameters

value
Type Value to check

Returns

boolean True if value is power of 2

See

https://voltaire.tevm.sh/primitives/uint for Uint documentation

Since

0.0.0

Throws

Example

import * as Uint256 from './primitives/Uint/index.js';
Uint256.isPowerOf2(Uint256.from(16n)); // true
Uint256.isPowerOf2(Uint256.from(15n)); // false

isValid()

isValid(value): value is Type
Defined in: src/primitives/Uint/isValid.ts:16 Check if value is a valid Uint256

Parameters

value
unknown Value to check

Returns

value is Type true if value is valid Uint256

Example

const isValid = Uint.isValid(100n); // true
const isInvalid = Uint.isValid(-1n); // false

isZero()

isZero(uint): boolean
Defined in: src/primitives/Uint/isZero.ts:16 Check if value is zero

Parameters

uint
Type Value to check

Returns

boolean true if uint === 0

Example

const a = Uint(0n);
const isZero1 = Uint.isZero(a); // true
const isZero2 = a.isZero(); // true

lcm()

lcm(a, b): Type
Defined in: src/primitives/Uint/lcm.js:19 Calculate least common multiple

Parameters

a
Type First value
b
Type Second value

Returns

Type LCM of a and b

See

https://voltaire.tevm.sh/primitives/uint for Uint documentation

Since

0.0.0

Throws

Example

import * as Uint256 from './primitives/Uint/index.js';
const result = Uint256.lcm(Uint256.from(12n), Uint256.from(18n)); // 36n

leadingZeros()

leadingZeros(uint): number
Defined in: src/primitives/Uint/leadingZeros.ts:17 Get number of leading zero bits

Parameters

uint
Type Value to check

Returns

number Number of leading zeros (0-256)

Example

const a = Uint(1n);
const zeros1 = Uint.leadingZeros(a); // 255
const zeros2 = a.leadingZeros(); // 255

lessThan()

lessThan(uint, b): boolean
Defined in: src/primitives/Uint/lessThan.ts:18 Check less than

Parameters

uint
Type First value
b
Type Second value

Returns

boolean true if uint < b

Example

const a = Uint(100n);
const b = Uint(200n);
const isLess1 = Uint.lessThan(a, b); // true
const isLess2 = a.lessThan(b); // true

lessThanOrEqual()

lessThanOrEqual(uint, b): boolean
Defined in: src/primitives/Uint/lessThanOrEqual.ts:18 Check less than or equal

Parameters

uint
Type First value
b
Type Second value

Returns

boolean true if uint is less than or equal to b

Example

const a = Uint(100n);
const b = Uint(100n);
const isLte1 = Uint.lessThanOrEqual(a, b); // true
const isLte2 = a.lessThanOrEqual(b); // true

max()

max(…values): Type
Defined in: src/primitives/Uint/max.js:17 Find maximum of multiple Uint256 values

Parameters

values
Type[] Values to compare

Returns

Type Maximum value

See

https://voltaire.tevm.sh/primitives/uint for Uint documentation

Since

0.0.0

Throws

If no values provided

Example

import * as Uint256 from './primitives/Uint/index.js';
const result = Uint256.max(Uint256.from(100n), Uint256.from(50n), Uint256.from(75n)); // 100n

maximum()

maximum(uint, b): Type
Defined in: src/primitives/Uint/maximum.ts:18 Get maximum of two values

Parameters

uint
Type First value
b
Type Second value

Returns

Type max(uint, b)

Example

const a = Uint(100n);
const b = Uint(200n);
const max1 = Uint.maximum(a, b); // 200
const max2 = a.maximum(b); // 200

min()

min(…values): Type
Defined in: src/primitives/Uint/min.js:15 Find minimum of multiple Uint256 values

Parameters

values
Type[] Values to compare

Returns

Type Minimum value

See

https://voltaire.tevm.sh/primitives/uint for Uint documentation

Since

0.0.0

Throws

If no values provided

Example

import * as Uint256 from './primitives/Uint/index.js';
const result = Uint256.min(Uint256.from(100n), Uint256.from(50n), Uint256.from(75n)); // 50n

minimum()

minimum(uint, b): Type
Defined in: src/primitives/Uint/minimum.ts:18 Get minimum of two values

Parameters

uint
Type First value
b
Type Second value

Returns

Type min(uint, b)

Example

const a = Uint(100n);
const b = Uint(200n);
const min1 = Uint.minimum(a, b); // 100
const min2 = a.minimum(b); // 100

minus()

minus(uint, b): Type
Defined in: src/primitives/Uint/minus.ts:19 Subtract Uint256 value with wrapping

Parameters

uint
Type First operand
b
Type Second operand

Returns

Type Difference (uint - b) mod 2^256

Example

const a = Uint(100n);
const b = Uint(50n);
const diff1 = Uint.minus(a, b); // 50
const diff2 = a.minus(b); // 50

modulo()

modulo(uint, b): Type
Defined in: src/primitives/Uint/modulo.ts:19 Modulo operation

Parameters

uint
Type Dividend
b
Type Divisor

Returns

Type Remainder (uint % b)

Throws

Error if divisor is zero

Example

const a = Uint(100n);
const b = Uint(30n);
const remainder1 = Uint.modulo(a, b); // 10
const remainder2 = a.modulo(b); // 10

notEquals()

notEquals(uint, b): boolean
Defined in: src/primitives/Uint/notEquals.ts:18 Check inequality

Parameters

uint
Type First value
b
Type Second value

Returns

boolean true if uint !== b

Example

const a = Uint(100n);
const b = Uint(200n);
const isNotEq1 = Uint.notEquals(a, b); // true
const isNotEq2 = a.notEquals(b); // true

plus()

plus(uint, b): Type
Defined in: src/primitives/Uint/plus.ts:19 Add Uint256 value with wrapping

Parameters

uint
Type First operand
b
Type Second operand

Returns

Type Sum (uint + b) mod 2^256

Example

const a = Uint(100n);
const b = Uint(50n);
const sum1 = Uint.plus(a, b); // 150
const sum2 = a.plus(b); // 150

popCount()

popCount(uint): number
Defined in: src/primitives/Uint/popCount.ts:16 Count number of set bits (population count)

Parameters

uint
Type Value to check

Returns

number Number of 1 bits

Example

const a = Uint(0xffn);
const count1 = Uint.popCount(a); // 8
const count2 = a.popCount(); // 8

product()

product(…values): Type
Defined in: src/primitives/Uint/product.js:17 Multiply multiple Uint256 values with wrapping

Parameters

values
Type[] Values to multiply

Returns

Type Product of all values mod 2^256

See

https://voltaire.tevm.sh/primitives/uint for Uint documentation

Since

0.0.0

Throws

Example

import * as Uint256 from './primitives/Uint/index.js';
const result = Uint256.product(Uint256.from(10n), Uint256.from(5n), Uint256.from(2n)); // 100n

shiftLeft()

shiftLeft(uint, bits): Type
Defined in: src/primitives/Uint/shiftLeft.ts:19 Left shift

Parameters

uint
Type Value to shift
bits
Type Number of bits to shift

Returns

Type uint shifted left by bits (mod 2^256)

Example

const a = Uint(1n);
const b = Uint(8n);
const result1 = Uint.shiftLeft(a, b); // 256
const result2 = a.shiftLeft(b); // 256

shiftRight()

shiftRight(uint, bits): Type
Defined in: src/primitives/Uint/shiftRight.ts:18 Right shift

Parameters

uint
Type Value to shift
bits
Type Number of bits to shift

Returns

Type uint shifted right by bits

Example

const a = Uint(256n);
const b = Uint(8n);
const result1 = Uint.shiftRight(a, b); // 1
const result2 = a.shiftRight(b); // 1

sum()

sum(…values): Type
Defined in: src/primitives/Uint/sum.js:17 Sum multiple Uint256 values with wrapping

Parameters

values
Type[] Values to sum

Returns

Type Sum of all values mod 2^256

See

https://voltaire.tevm.sh/primitives/uint for Uint documentation

Since

0.0.0

Throws

Example

import * as Uint256 from './primitives/Uint/index.js';
const result = Uint256.sum(Uint256.from(100n), Uint256.from(50n), Uint256.from(25n)); // 175n

times()

times(uint, b): Type
Defined in: src/primitives/Uint/times.ts:19 Multiply Uint256 value with wrapping

Parameters

uint
Type First operand
b
Type Second operand

Returns

Type Product (uint * b) mod 2^256

Example

const a = Uint(10n);
const b = Uint(5n);
const product1 = Uint.times(a, b); // 50
const product2 = a.times(b); // 50

toAbiEncoded()

toAbiEncoded(uint): Uint8Array
Defined in: src/primitives/Uint/toAbiEncoded.ts:20 Convert Uint256 to ABI-encoded bytes (32 bytes, big-endian) This is identical to toBytes() - all Uint256 values in ABI encoding are represented as 32-byte big-endian values.

Parameters

uint
Type Uint256 value to encode

Returns

Uint8Array 32-byte ABI-encoded Uint8Array

Example

const value = Uint(255n);
const encoded1 = Uint.toAbiEncoded(value);
const encoded2 = value.toAbiEncoded();

toBigInt()

toBigInt(uint): bigint
Defined in: src/primitives/Uint/toBigInt.ts:16 Convert Uint256 to bigint

Parameters

uint
Type Uint256 value to convert

Returns

bigint bigint value

Example

const value = Uint(255n);
const bigint1 = Uint.toBigInt(value);
const bigint2 = value.toBigInt();

toBytes()

toBytes(uint): Uint8Array
Defined in: src/primitives/Uint/toBytes.ts:16 Convert Uint256 to bytes (big-endian, 32 bytes)

Parameters

uint
Type Uint256 value to convert

Returns

Uint8Array 32-byte Uint8Array

Example

const value = Uint(255n);
const bytes1 = Uint.toBytes(value);
const bytes2 = value.toBytes();

toHex()

toHex(uint, padded): string
Defined in: src/primitives/Uint/toHex.ts:18 Convert Uint256 to hex string

Parameters

uint
Type Uint256 value to convert
padded
boolean = true Whether to pad to 64 characters (32 bytes)

Returns

string Hex string with 0x prefix

Example

const value = Uint(255n);
const hex1 = Uint.toHex(value); // "0x00...ff"
const hex2 = value.toHex(); // "0x00...ff"
const hex3 = value.toHex(false); // "0xff"

toNumber()

toNumber(uint): number
Defined in: src/primitives/Uint/toNumber.ts:17 Convert Uint256 to number

Parameters

uint
Type Uint256 value to convert

Returns

number number value

Throws

Error if value exceeds MAX_SAFE_INTEGER

Example

const value = Uint(255n);
const num1 = Uint.toNumber(value);
const num2 = value.toNumber();

toPower()

toPower(uint, exponent): Type
Defined in: src/primitives/Uint/toPower.ts:19 Exponentiation

Parameters

uint
Type Base value
exponent
Type Exponent value

Returns

Type uint^exponent mod 2^256

Example

const base = Uint(2n);
const exp = Uint(8n);
const result1 = Uint.toPower(base, exp); // 256
const result2 = base.toPower(exp); // 256

toString()

toString(uint, radix): string
Defined in: src/primitives/Uint/toString.ts:19 Convert Uint256 to string representation

Parameters

uint
Type Uint256 value to convert
radix
number = 10 Base for string conversion (2, 10, 16, etc.)

Returns

string String representation

Example

const value = Uint(255n);
const dec1 = Uint.toString(value, 10); // "255"
const dec2 = value.toString(10); // "255"
const hex = value.toString(16); // "ff"

tryFrom()

tryFrom(value): Type | undefined
Defined in: src/primitives/Uint/tryFrom.ts:17 Try to create Uint256, returns undefined if invalid (standard form)

Parameters

value
bigint, number, or string string | number | bigint

Returns

Type | undefined Uint256 value or undefined

Example

const a = Uint.tryFrom(100n); // Uint256
const b = Uint.tryFrom(-1n); // undefined
const c = Uint.tryFrom("invalid"); // undefined

References

Uint256

Renames and re-exports Uint256Type