Try it Live
Run Uint examples in the interactive playground
Uint64
A branded type for 64-bit unsigned integers (0 to 18,446,744,073,709,551,615). Represented as JavaScriptbigint to handle values beyond Number.MAX_SAFE_INTEGER.
Overview
Uint64Type provides:
- Compile-time type branding
- Range validation (0 to 2^64-1)
- Full arithmetic and bitwise operations
- Safe handling of large values via
bigint
Type Definition
Range
- Minimum: 0
- Maximum: 18,446,744,073,709,551,615 (2^64 - 1)
- Size: 64 bits (8 bytes)
Constants
Construction
from
Create from bigint, number, or string:fromBigInt
fromNumber
fromHex
fromBytes
Create from Uint8Array (big-endian, up to 8 bytes):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
plus
minus
times
dividedBy
modulo
toPower
Comparison
equals
lessThan / greaterThan
isZero
minimum / maximum
Bitwise Operations
bitwiseAnd / bitwiseOr / bitwiseXor
bitwiseNot
shiftLeft / shiftRight
Bit Analysis
bitLength
leadingZeros
popCount
Validation
isValid
Use Cases
- Nanosecond timestamps: High-precision timing
- File sizes: Large file sizes in bytes
- Database IDs: Auto-incrementing identifiers
- Counters: Large event counters
- Cumulative gas: Total gas across many transactions
- Token supply: Tokens with high supply counts
Example: High-Precision Timing
Example: Large File Handling
Why Uint64 Uses BigInt
JavaScript’sNumber type can only safely represent integers up to 2^53-1 (9,007,199,254,740,991). Since Uint64’s maximum value is 2^64-1, it requires bigint for accurate representation:
API Reference
| Category | Methods |
|---|---|
| Construction | from, fromNumber, fromBigInt, fromHex, fromBytes, fromAbiEncoded, tryFrom |
| Conversion | toNumber, toBigInt, toHex, toBytes, toAbiEncoded, toString, clone |
| Arithmetic | plus, minus, times, dividedBy, modulo, toPower |
| Comparison | equals, lessThan, greaterThan, isZero, minimum, maximum |
| Bitwise | bitwiseAnd, bitwiseOr, bitwiseXor, bitwiseNot, shiftLeft, shiftRight |
| Bit Analysis | bitLength, leadingZeros, popCount |
| Validation | isValid |

