https://github.com/reecejohnson/eth-address
A lightweight library to format Ethereum addresses.
https://github.com/reecejohnson/eth-address
Last synced: 10 months ago
JSON representation
A lightweight library to format Ethereum addresses.
- Host: GitHub
- URL: https://github.com/reecejohnson/eth-address
- Owner: reecejohnson
- Created: 2021-08-26T09:12:50.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2023-01-18T07:14:28.000Z (over 3 years ago)
- Last Synced: 2025-10-04T09:54:17.079Z (10 months ago)
- Language: TypeScript
- Homepage:
- Size: 50.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://badge.fury.io/js/eth-address)

# eth-address
A lightweight library to format Ethereum addresses. Easily truncate any eth address to a desired length.
## Installation
### npm
```
npm install eth-address
```
### yarn
```
yarn add eth-address
```
## Functions
### formatEthereumAddress
```ts
formatEthAddress(address: string, chars: number = 4): string;
```
Formats a given Ethereum address at the desired length each side of the "..." separator.
## Usage
### Importing
#### JavaScript
```js
const formatEthAddress = require('eth-address');
```
#### JavaScript (ES6) / TypeScript
```ts
import { formatEthAddress } from 'eth-address';
```
### Example
```ts
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'
```