Skip to main content

Try it Live

Run Address examples in the interactive playground

AddressType

Tree-shakeable functional API for Address operations with optimal bundle size.

Overview

AddressType is the functional layer underlying the Address class. It provides:
  • Zero-overhead branded type wrapping Uint8Array (20 bytes)
  • Tree-shakeable individual function exports
  • Data-first unopinionated methods taking address as first parameter
  • Bundle optimization through selective imports
Primary benefit: When using tree-shakeable imports and avoiding methods that use keccak256 or RLP, those implementations are excluded from bundle.

Type Definition

AddressType (Uint8Array)

The core Address type is a branded 20-byte Uint8Array:
Properties:
  • Size: Always 20 bytes (160 bits)
  • Branding: Uses Symbol branding via brand symbol
  • Conceptual relation: Represents a fixed 20-byte value (conceptually like BrandedBytes<20>)
  • Type safety: Prevents accidental mixing with other Uint8Arrays
Defined in: primitives/Address/AddressType/AddressType.ts Related: Bytes32 - Similar pattern for 32-byte fixed values

HexAddress Variants

Address also provides hex string variants that extend Hex.Sized<20>:
Hex variants:
  • Base Hex.Sized<20>: 20-byte hex string type from Hex primitive using symbol branding
  • ChecksumAddress: EIP-55 checksummed (mixed case for integrity)
  • LowercaseAddress: All lowercase hex (e.g., "0x742d35cc...")
  • UppercaseAddress: All uppercase hex (e.g., "0x742D35CC...")
  • Symbol branding: Uses brand symbol (Symbol.for("type")) for nominal typing
See Hex for details on sized hex strings.

Available Functions

All Address functionality available as tree-shakeable functions:

Constructors

See Constructors for details.

Conversions

See Conversions for details. Tree-shaking note: toChecksummed includes keccak256.

Comparisons

See Comparisons for details.

Validation

See Validation for details. Tree-shaking note: isValidChecksum includes keccak256.

Contract Addresses

See Contract Addresses for details. Tree-shaking note: Both include keccak256. calculateCreateAddress also includes RLP.

Variants

These functions convert from AddressType (Uint8Array) to hex string variants (ChecksumAddress, LowercaseAddress, UppercaseAddress). See Variants for details.

Data-First Pattern

All AddressType functions follow data-first pattern:
This enables functional composition and partial application:

Tree-Shaking Benefits

Primary benefit: Selective inclusion of crypto dependencies

Example 1: Minimal Bundle (No Crypto)

Bundle: No keccak256, no RLP. Only basic conversions and comparisons.

Example 2: With Checksum (Keccak256 Only)

Bundle: Includes keccak256 for checksumming. No RLP.

Example 3: With CREATE (Keccak256 + RLP)

Bundle: Includes both keccak256 and RLP encoder.

Example 4: Address Class (Everything)

Bundle: Includes all Address methods, keccak256, and RLP (due to prototype methods).

Dependency Table

When to Use AddressType vs Address

Use AddressType When:

  • Bundle size critical (mobile, embedded)
  • Avoiding crypto dependencies
  • Functional style preferred
  • Selective imports desired
  • Composing functions heavily

Use Address Class When:

  • OOP style preferred
  • Ergonomics over bundle size
  • Using many methods (crypto already in bundle)
  • Type safety with prototype methods
  • Traditional API expected

Interoperability

AddressType and Address Class

AddressType and Address are fully compatible:

AddressType and Hex Variants

AddressType (Uint8Array) and hex string variants are separate types with conversion functions:
Type relationship:
  • AddressType: 20-byte Uint8Array (runtime data)
  • HexAddress variants: Hex.Sized (20-byte) strings (display/serialization)

Constants

Address Documentation: Related Primitives:
  • Hex - Hex string types (Hex.Sized<20> used by hex variants)
  • Bytes32 - Similar pattern for 32-byte fixed values
  • Bytes16 - Similar pattern for 16-byte fixed values