Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/reecejohnson/eth-address
A lightweight library to format Ethereum addresses.
https://github.com/reecejohnson/eth-address
Last synced: 14 days 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 (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-01-18T07:14:28.000Z (about 2 years ago)
- Last Synced: 2024-12-20T01:35:47.681Z (about 2 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
[![npm version](https://badge.fury.io/js/eth-address.svg)](https://badge.fury.io/js/eth-address)
![downloads](https://img.shields.io/npm/dw/eth-address)
# eth-addressA 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'
```