A lightweight library to format Ethereum addresses. Easily truncate any eth address to a desired length.
npm install eth-address
yarn add eth-address
formatEthAddress(address: string, chars: number = 4): string;
Formats a given Ethereum address at the desired length each side of the "..." separator.
const formatEthAddress = require('eth-address');
import { formatEthAddress } from 'eth-address';
import { formatEthAddress } from 'eth-address';
const address = '0x61289A6b7819203749E409c7d62427Df7aD36dD7';
const formattedAddressWithDefaultChars = formatEthAddress(address);
// formattedAddressWithDefaultChars result
'0x6128...6dD7'
const charactersASide = 6;
const formattedAddressWith6Chars = formatEthAddress(address, charactersASide);
// formattedAddressWith6Chars result
'0x61289A...D36dD7'