Skip to main content

Try it Live

Run Uint examples in the interactive playground

Uint.fromAbiEncoded(bytes: Uint8Array): BrandedUint256

Create Uint256 from ABI-encoded bytes. Requires exactly 32 bytes. Parameters:
  • bytes: Uint8Array - ABI-encoded bytes (exactly 32 bytes, big-endian)
Returns: BrandedUint256 - Uint256 as branded Uint8Array Example:
Defined in: primitives/Uint/fromAbiEncoded.ts

ABI Encoding Format

Solidity ABI encoding for uint256:
  • Always 32 bytes (256 bits)
  • Big-endian byte order
  • Left-padded with zeros for smaller values

Examples

Strict Length Requirement

Unlike fromBytes (1-32 bytes), fromAbiEncoded requires exactly 32 bytes:

Why Strict?

ABI encoding has fixed-size slots for type safety:

Decoding ABI Data

Function Return Values

Event Log Data

Multiple uint256 Values

Usage Patterns

ABI Decoder Helper

Contract Interaction

Type-Safe Validation

Performance

fromAbiEncoded is zero-copy - the input bytes are used directly as internal storage (no allocation needed). For decoding large batches of uint256 values, this is the most efficient method.

See Also