# multiaddr

> multiaddr implementation (binary + string representation of network addresses)

Latest version **10.0.1** (published 2021-08-19) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install multiaddr
pnpm add multiaddr
yarn add multiaddr
bun add multiaddr
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 10.0.1 |
| Published | 2021-08-19 |
| First published | 2014-06-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 95.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 108 |
| Maintainers | jacobheun, daviddias, achingbrain, alanshaw, vascosantos |
| Keywords | multiaddr, binary, string |

## Links

- npm: https://www.npmjs.com/package/multiaddr
- Repository: https://github.com/multiformats/js-multiaddr
- Issues: https://github.com/multiformats/js-multiaddr/issues
- npm.io page: https://npm.io/package/multiaddr

## Dependencies (6)

- [is-ip](https://npm.io/package/is-ip.md) ^3.1.0
- [varint](https://npm.io/package/varint.md) ^6.0.0
- [err-code](https://npm.io/package/err-code.md) ^3.0.1
- [uint8arrays](https://npm.io/package/uint8arrays.md) ^3.0.0
- [multiformats](https://npm.io/package/multiformats.md) ^9.4.5
- [dns-over-http-resolver](https://npm.io/package/dns-over-http-resolver.md) ^1.2.3

## Alternatives

- [@mce/gif](https://npm.io/package/@mce/gif.md) — 2.6K weekly downloads
- [cleanse](https://npm.io/package/cleanse.md) — 173 weekly downloads
- [str](https://npm.io/package/str.md) — 127 weekly downloads
- [naming](https://npm.io/package/naming.md) — 95 weekly downloads
- [tap-telco-api](https://npm.io/package/tap-telco-api.md) — 19 weekly downloads

## Recent versions

- 10.0.1 (latest) — 2021-08-19
- 10.0.0 — 2021-07-06
- 9.0.2 — 2021-06-23
- 9.0.1 — 2021-04-08
- 9.0.0 — 2021-04-08
- 8.1.2 — 2020-12-11
- 8.1.1 — 2020-10-30
- 8.1.0 — 2020-10-29
- 8.0.0 — 2020-08-07
- 7.5.0 — 2020-06-25
- 7.4.3 — 2020-03-26
- 7.4.2 — 2020-03-18
- 7.4.1 — 2020-03-16
- 7.4.0 — 2020-02-28
- 7.3.1 — 2020-02-13
- … 47 more at https://npm.io/package/multiaddr/versions

## README

js-multiaddr
============

[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io)
[![](https://img.shields.io/badge/project-multiformats-blue.svg?style=flat-square)](https://github.com/multiformats/multiformats)
[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](https://webchat.freenode.net/?channels=%23ipfs)
[![Dependency Status](https://david-dm.org/multiformats/js-multiaddr.svg?style=flat-square)](https://david-dm.org/multiformats/js-multiaddr)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
[![](https://img.shields.io/badge/readme%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)
[![](https://img.shields.io/travis/multiformats/js-multiaddr.svg?style=flat-square)](https://travis-ci.com/multiformats/js-multiaddr)
[![codecov](https://img.shields.io/codecov/c/github/multiformats/js-multiaddr.svg?style=flat-square)](https://codecov.io/gh/multiformats/js-multiaddr)

> JavaScript implementation of [multiaddr](https://github.com/multiformats/multiaddr).

## Lead Maintainer

[Jacob Heun](https://github.com/jacobheun)

## Table of Contents

- [js-multiaddr](#js-multiaddr)
  - [Lead Maintainer](#lead-maintainer)
  - [Table of Contents](#table-of-contents)
  - [Background](#background)
    - [What is multiaddr?](#what-is-multiaddr)
  - [Install](#install)
    - [NPM](#npm)
    - [Browser: `<script>` Tag](#browser-script-tag)
  - [Usage](#usage)
  - [API](#api)
  - [Resolvers](#resolvers)
  - [Contribute](#contribute)
  - [License](#license)

## Background

### What is multiaddr?

A standard way to represent addresses that

- support any standard network protocol
- are self-describing
- have a binary packed format
- have a nice string representation
- encapsulate well

## Install

### NPM
```sh
npm i multiaddr
```

### Browser: `<script>` Tag

Loading this module through a script tag will make the `Multiaddr` obj available in
the global namespace.

```html
<script src="https://unpkg.com/multiaddr/dist/index.min.js"></script>
```

## Usage

```js
// if we are coming from <= 8.x you can use the factory function 
const { multiaddr } = require('multiaddr')
const addr =  multiaddr("/ip4/127.0.0.1/udp/1234")
// <Multiaddr /ip4/127.0.0.1/udp/1234>

// or just the class directly
const { Multiaddr } = require('multiaddr')

const addr = new Multiaddr("/ip4/127.0.0.1/udp/1234")
// <Multiaddr /ip4/127.0.0.1/udp/1234>

addr.bytes
// <Uint8Array 04 7f 00 00 01 11 04 d2>

addr.toString()
// '/ip4/127.0.0.1/udp/1234'

addr.protos()
/* 
[
  {code: 4, name: 'ip4', size: 32},
  {code: 273, name: 'udp', size: 16}
]
*/

// gives you an object that is friendly with what Node.js core modules expect for addresses
addr.nodeAddress()
/*
{
  family: 4,
  port: 1234,
  address: "127.0.0.1"
}
*/

addr.encapsulate('/sctp/5678')
// <Multiaddr /ip4/127.0.0.1/udp/1234/sctp/5678>
```

## API

https://multiformats.github.io/js-multiaddr/

## Resolvers

`multiaddr` allows multiaddrs to be resolved when appropriate resolvers are provided. This module already has resolvers available, but you can also create your own.  Resolvers should always be set in the same module that is calling `multiaddr.resolve()` to avoid conflicts if multiple versions of `multiaddr` are in your dependency tree. 
To provide multiaddr resolvers you can do:

```js
const { Multiaddr } = require('multiaddr')
const resolvers = require('multiaddr/src/resolvers')

Multiaddr.resolvers.set('dnsaddr', resolvers.dnsaddrResolver)
```

The available resolvers are:

|     Name    | type | Description |
|-------------|------|-------------|
| `dnsaddrResolver` | `dnsaddr` | dnsaddr resolution with TXT Records |

A resolver receives a `Multiaddr` as a parameter and returns a `Promise<Array<string>>`.

## Contribute

Contributions welcome. Please check out [the issues](https://github.com/multiformats/js-multiaddr/issues).

Check out our [contributing document](https://github.com/multiformats/multiformats/blob/master/contributing.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to multiformats are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).

Small note: If editing the README, please conform to the [standard-readme](https://github.com/RichardLitt/standard-readme) specification.

## License

[MIT](LICENSE) © 2016 Protocol Labs Inc.

---
_Source: https://npm.io/package/multiaddr · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
