Try it Live
Run Uint examples in the interactive playground
Conceptual Guide - For API reference and method documentation, see Uint API.
What Are Unsigned Integers?
An unsigned integer is a whole number (0, 1, 2, 3, …) with no negative values. The EVM uses unsigned integers for:- Token amounts and balances
- Gas prices and limits
- Block numbers and timestamps
- Nonces and counters
- Storage slot indices
EVM Integer Types
The EVM supports unsigned integers from 8 to 256 bits in 8-bit increments:Why uint256?
Most Ethereum operations useuint256 (32 bytes) because:
- EVM stack operates on 256-bit words
- Efficient for large numbers (token amounts, wei)
- Storage slots are 32 bytes
- Cryptographic operations use 256-bit values
Creating Uints
- From Bigint
- From Hex
- From Number
- From Bytes
Big-Endian Encoding
The EVM stores unsigned integers in big-endian format: most significant byte first.Arithmetic Operations
All arithmetic wraps on overflow (mod 2^256), matching EVM behavior:- Basic Arithmetic
- Overflow Wrapping
- Safe Arithmetic
Comparisons
- Equality
- Ordering
- Sorting
Bitwise Operations
- Logical Operations
- Bit Shifts
- Bit Manipulation
Size Variants and Padding
While Tevm focuses on uint256, you can work with smaller sizes:Common Use Cases
- Token Amounts
- Wei/Ether Conversions
- Gas Calculations
- Timestamps
JavaScript Number Limitations
CRITICAL: JavaScript numbers are 64-bit floats, only precise up to 2^53-1 (9,007,199,254,740,991).Conversions
- To Hex
- To Number/BigInt
- To Bytes
- To String
Resources
- Solidity Types - Solidity unsigned integer documentation
- EVM Integer Opcodes - ADD, MUL, DIV, MOD, EXP, etc.
- Ethereum Yellow Paper - Formal arithmetic specifications (Section 9.1)
- MDN BigInt - JavaScript BigInt reference
Next Steps
- Overview - Type definition and API reference
- Arithmetic - Detailed arithmetic operations
- Bitwise - Bitwise operations and bit manipulation
- Comparisons - Equality and ordering
- Conversions - Format conversions

