Address & hash
Two helpers for displaying hex strings in the UI.
import { shortenAddress, minifyHash } from "@symmio/utils/address";shortenAddress
Checksum + slice an EVM address. Use this for EOA / contract addresses where you want EIP-55 mixed-case output.
shortenAddress("0x46493c376758da47823d7e3ae5d417ea6546eeb3");
// "0x4649…eEB3"
shortenAddress(addr, { chars: 6, ellipsis: "..." });
// "0x46493c...46eEB3"The address is checksummed via viem’s getAddress before slicing — so the output matches what a block explorer would render. Invalid addresses throw viem’s InvalidAddressError.
Options
interface ShortenAddressOptions {
chars?: number; // characters on each side of the ellipsis (default 4)
ellipsis?: string; // default "…" (typographic horizontal ellipsis)
}minifyHash
Generic hex shortener. Use for non-address strings: transaction hashes, ABI selectors, signatures, etc. Does not checksum (it’s not an address).
minifyHash("0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef");
// "0x1234...cdef"
minifyHash(null); // "—"
minifyHash(undefined, { placeholder: "n/a" }); // "n/a"
minifyHash(hash, { start: 4, end: 6, ellipsis: "…" });
// "0x12…abcdef"Returns an em-dash (—) by default for nullish input so UI placeholders stay one-line-safe.
Options
interface MinifyHashOptions {
start?: number; // characters from the start including "0x" prefix (default 6)
end?: number; // characters from the end (default 4)
ellipsis?: string; // default "..."
placeholder?: string; // for nullish input (default "—")
}When to use which
| Have | Use |
|---|---|
| EVM address | shortenAddress (checksummed) |
| Tx hash, selector, signature, any hex | minifyHash (generic) |
Last updated on