Format Wallet Address
Solana wallet addresses are long (typically 44 characters), which can make for a poor user experience when displayed in full. Many apps abbreviate addresses by showing only the first few and last few characters with an ellipsis in between (e.g., 7xKXt...9mN2v). This provides a better UI while still allowing users to identify addresses at a glance.
Code Snippet
Here's a ready-to-copy code snippet you can use in your application:
Usage
The function takes three parameters:
address- The full wallet address stringstartLength- Number of characters to show at the start (default: 4)endLength- Number of characters to show at the end (default: 4)
Example:
formatWalletAddress('7xKXtYrFJ8Jh1U8jZ2v9mN2vK3pL4qR5sT6uV7wX8yZ9aB0cD1eF2gH3iJ4k', 4, 4) Returns: 7xKX...iJ4k
