Skip to main content

Try it Live

Run Address examples in the interactive playground
This page is a placeholder. All examples on this page are currently AI-generated and are not correct. This documentation will be completed in the future with accurate, tested examples.
View the complete executable example at playground/src/examples/primitives/address/from-number.ts.

    Bit Masking

    Takes lower 160 bits (20 bytes) of input value. Higher bits are discarded. Formula: address = value & ((1 << 160) - 1) Examples:

    Use Cases

    Sequential Addresses

    Generate sequential addresses for testing:

    Address Arithmetic

    Perform arithmetic on addresses:

    Numeric Conversions

    Convert between numeric and address representations:

    Test Fixtures

    Create predictable test addresses:

    Number vs Bigint

    Number (JavaScript): Safe for values up to 2^53 - 1:
    Bigint: Required for larger values:
    Recommendation: Use bigint for address-sized values (160 bits).

    Error Handling

    Overflow Behavior

    Values larger than 160 bits are truncated (not an error):

    Comparison with Other Constructors

    When to use fromNumber():
    • Have numeric value
    • Performing address arithmetic
    • Generating test addresses
    • Converting from U256
    When to use other constructors:
    • fromHex() - Have hex string
    • fromBytes() - Have byte array
    • from() - Type unknown or mixed inputs

    See Also