Overview
The Nexus SDK provides utilities for validating and formatting Ethereum addresses for display.isValidAddress
Validate whether a string is a valid Ethereum address.Parameters
The address string to validate
Returns
true if the address is valid, false otherwiseValidation Rules
The function checks:- Correct length (42 characters including
0xprefix) - Valid hexadecimal characters
- Proper checksum (EIP-55)
Examples
truncateAddress
Truncate an Ethereum address for display purposes.Parameters
The Ethereum address to truncate
Number of characters to keep from the start (including
0x)Number of characters to keep from the end
Returns
The truncated address string with ellipsis in the middle
Behavior
- If the address is invalid, returns the original string unchanged
- If the address is shorter than
startLength + endLength + 2, returns it unchanged - Validates the address before truncating
Examples
Common Patterns
Best Practices
Always validate before using
Use
isValidAddress() to validate user input before passing addresses to SDK methods.Truncate for display only
Only use
truncateAddress() for UI display. Always store and use full addresses in your application logic.Show full address on hover
Use the
title attribute or a tooltip to show the full address when users hover over truncated addresses.Adjust for screen size
Use shorter truncation (e.g., 4/2) for mobile displays and longer truncation (6/4) for desktop.