Created
February 14, 2022 14:29
-
-
Save ibelick/8ac06c0401b593785ce86ade796eaa0c to your computer and use it in GitHub Desktop.
utility to truncate Ethereum addresses to a more readable format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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