Uint (Uint256)
A branded type for 256-bit unsigned integers - the native word size of the EVM. Represented as JavaScriptbigint with compile-time type safety.
Overview
Uint256Type provides:
- Compile-time type branding
- Range validation (0 to 2^256-1)
- Full arithmetic operations with overflow checking
- Bitwise operations
- Comparison operators
- Conversion utilities
Type Definition
Range
- Minimum: 0
- Maximum: 2^256 - 1 (115792089237316195423570985008687907853269984665640564039457584007913129639935)
- Size: 256 bits (32 bytes)
Constants
Construction
from
Create from bigint, number, or string:fromBigInt
Create from bigint:fromNumber
Create from number:fromHex
Create from hex string:fromBytes
Create from Uint8Array (big-endian):fromAbiEncoded
Create from 32-byte ABI-encoded data:tryFrom
Safe construction that returns undefined on invalid input:Conversion
toBigInt
toNumber
toHex
toBytes
toAbiEncoded
toString
Arithmetic
All operations validate results stay within valid range.plus
minus
times
dividedBy
modulo
toPower
sum (variadic)
product (variadic)
Comparison
equals / notEquals
lessThan / lessThanOrEqual
greaterThan / greaterThanOrEqual
isZero
minimum / maximum
min / max (variadic)
Bitwise Operations
bitwiseAnd
bitwiseOr
bitwiseXor
bitwiseNot
shiftLeft / shiftRight
Bit Analysis
bitLength
Number of bits needed to represent value:leadingZeros
Count leading zero bits:popCount
Count set bits (population count):isPowerOf2
Number Theory
gcd
Greatest common divisor:lcm
Least common multiple:Validation
isValid
Use Cases
- EVM stack values and memory words
- Token amounts and balances
- Storage slot values
- Block numbers and timestamps
- Gas calculations
- Cryptographic operations

