Try it Live
Run Uint examples in the interactive playground
Type Definition
Brandedbigint representing unsigned 256-bit integer (0 to 2^256-1). Supports tree-shakeable namespace methods and class instances with automatic wrapping on overflow.
Quick Reference
Effect Schema
API Methods
Constructors
from(value)- Universal constructor from bigint, number, or stringfromHex(hex)- Parse hex string (with or without 0x prefix)fromBigInt(value)- Create from bigint with validationfromNumber(value)- Create from number (throws if out of range)fromBytes(bytes)- Parse from Uint8Array (big-endian)fromAbiEncoded(bytes)- Parse ABI-encoded uint256tryFrom(value)- Safe constructor returning undefined on error
Conversions
toHex(uint, padded?)- Convert to hex string with optional paddingtoBigInt(uint)- Convert to biginttoNumber(uint)- Convert to number (throws if > MAX_SAFE_INTEGER)toBytes(uint)- Convert to Uint8Array (32 bytes, big-endian)toAbiEncoded(uint)- Convert to ABI-encoded bytestoString(uint, radix?)- Convert to string with optional radix (2-36)
Arithmetic
plus(a, b)- Addition with wrapping on overflowminus(a, b)- Subtraction with wrapping on underflowtimes(a, b)- Multiplication with wrapping on overflowdividedBy(a, b)- Division (throws on divide by zero)modulo(a, b)- Modulo operationtoPower(base, exponent)- Exponentiation with wrapping on overflow
Bitwise
bitwiseAnd(a, b)- Bitwise AND operationbitwiseOr(a, b)- Bitwise OR operationbitwiseXor(a, b)- Bitwise XOR operationbitwiseNot(value)- Bitwise NOT (one’s complement)shiftLeft(value, bits)- Left shift with wrappingshiftRight(value, bits)- Right shift (logical)
Comparisons
equals(a, b)- Check equalitylessThan(a, b)- Check if a < bgreaterThan(a, b)- Check if a > b
Validation
isValid(value)- Check if value is valid uint256
Utilities
isZero(value)- Check if value is zerominimum(a, b)- Return smaller of two valuesmaximum(a, b)- Return larger of two valuesbitLength(value)- Count significant bits (1-256)leadingZeros(value)- Count leading zero bitspopCount(value)- Count number of 1 bits
Types
- class Uint
- type BrandedUint256
Constants
Uint module exports constants for validation and arithmetic:Uint.MAX = 2^256 - 1- Maximum Uint256 value (115792089237316195423570985008687907853269984665640564039457584007913129639935n)Uint.MIN = 0- Minimum Uint256 valueUint.ZERO = 0- Zero constantUint.ONE = 1- One constantUint.SIZE = 32- Size in bytes
Wrapping Arithmetic
All arithmetic wraps on overflow (mod 2^256), matching EVM behavior:Tree-Shaking
Import only what you need for optimal bundle size:Related
- Fundamentals - Learn unsigned integers and EVM types
- Hex - Hex string encoding and decoding
- Keccak256 - Keccak256 hashing
- Branded Types - Zero-overhead type branding pattern
Specification
- Solidity Types - Unsigned integer documentation
- EVM Opcodes - ADD, MUL, DIV, MOD, EXP operations
- Ethereum Yellow Paper - Formal arithmetic specification (Section 9.1)

