Skip to content

Instantly share code, notes, and snippets.

@ibelick
Created February 14, 2022 14:29
Show Gist options
  • Save ibelick/8ac06c0401b593785ce86ade796eaa0c to your computer and use it in GitHub Desktop.
Save ibelick/8ac06c0401b593785ce86ade796eaa0c to your computer and use it in GitHub Desktop.
utility to truncate Ethereum addresses to a more readable format
export const truncateEthAddress = (address: string) => {
const truncateRegex = /^(0x[a-zA-Z0-9]{4})[a-zA-Z0-9]+([a-zA-Z0-9]{4})$/;
const match = address.match(truncateRegex);
if (!match) return address;
return `${match[1]}…${match[2]}`;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment