API ReferenceAdvanced utilities and typesFunction
shortenAddress()
function shortenAddress(address, maxLength?): string;Shortens a string to a maxLength by replacing the middle of it with ....
Note: when maxLength < 4 there isn’t enough room to fit an ellipsis-bearing truncation, so the
address is returned unchanged. In that regime this function cannot guarantee its output is
<= maxLength — only that it never truncates to something longer than the untruncated input.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
address | string | undefined | Address-like string to shorten via ellipses. |
maxLength | number | 12 | The maximum length the truncated string should be. This value determines how many characters of the string are actually shown. Note that the value does not include the horizontal ellipsis character. If the value is odd, it will be rounded down to the nearest even. |
Returns
string
The truncated string