# bitcoin-address-validation

> Validate any Bitcoin address - P2WSH, P2WPKH, P2SH, P2PKH - Mainnet & Testnet

Latest version **4.0.0** (published 2026-09-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install bitcoin-address-validation
pnpm add bitcoin-address-validation
yarn add bitcoin-address-validation
bun add bitcoin-address-validation
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2026-09-18 |
| First published | 2018-06-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=18.8.0 |
| Dependencies | 3 |
| Unpacked size | 19.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 126 |
| Author | Rui Gomes |
| Maintainers | ruigomes |
| Keywords | address, bitcoin, btc, validation, mainnet, testnet, bech32, p2sh, p2wpkh, p2wsh, p2pkh |

## Links

- npm: https://www.npmjs.com/package/bitcoin-address-validation
- Repository: https://github.com/ruigomeseu/bitcoin-address-validation
- Issues: https://github.com/ruigomeseu/bitcoin-address-validation/issues
- npm.io page: https://npm.io/package/bitcoin-address-validation

## Dependencies (3)

- [bech32](https://npm.io/package/bech32.md) ^2.0.0
- [base58-js](https://npm.io/package/base58-js.md) ^3.0.3
- [sha256-uint8array](https://npm.io/package/sha256-uint8array.md) ^0.12.1

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 4.0.0 (latest) — 2026-09-18
- 3.0.1 — 2026-09-09
- 3.0.0 — 2025-02-13
- 2.2.3 — 2023-08-01
- 2.2.2 — 2023-08-01
- 2.2.1 — 2022-01-24
- 2.2.0 — 2021-12-21
- 2.1.1 — 2021-11-17
- 2.1.0 — 2021-05-24
- 2.0.1 — 2021-02-20
- 2.0.0 — 2021-02-20
- 1.0.2 — 2020-04-13
- 1.0.1 — 2020-02-04
- 1.0.0 — 2019-09-27
- 0.2.9 — 2019-08-05
- … 13 more at https://npm.io/package/bitcoin-address-validation/versions

## README

# bitcoin-address-validation

[![npm version](https://badge.fury.io/js/bitcoin-address-validation.svg)](https://www.npmjs.com/package/bitcoin-address-validation)
[![npm](https://img.shields.io/npm/dw/bitcoin-address-validation.svg)](https://www.npmjs.com/package/bitcoin-address-validation)
[![Twitter Follow](https://img.shields.io/twitter/follow/8bitgomes.svg?style=social)](https://twitter.com/8bitgomes)

Validate Bitcoin addresses - P2WSH, P2WPKH, P2PKH, P2SH and P2TR.

```js
validate('bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4');
==> true

getAddressInfo('bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4');
==> { 
  bech32: true,
  network: 'mainnet',
  address: 'bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4',
  type: 'p2wpkh'
}
```

## Installation
Node.js 18.8 or newer is required when using this library in Node.js.

Add `bitcoin-address-validation` to your Javascript project dependencies using Yarn:
```bash
yarn add bitcoin-address-validation
```
Or NPM:
```bash
npm install bitcoin-address-validation --save
```

## Usage

### Importing

```js
import { validate, getAddressInfo } from 'bitcoin-address-validation';
```

### Validating addresses

`validate(address)` returns `true` for valid Bitcoin addresses or `false` for invalid Bitcoin addresses.

```js
validate('17VZNX1SN5NtKa8UQFxwQbFeFc3iqRYhem')
==> true

validate('invalid')
==> false
```

#### Network validation

`validate(address, network)` allows you to validate whether an address is valid and belongs to `network`.

```js
validate('36bJ4iqZbNevh9b9kzaMEkXb28Gpqrv2bd', 'mainnet')
==> true

validate('36bJ4iqZbNevh9b9kzaMEkXb28Gpqrv2bd', 'testnet')
==> false

validate('2N4RsPe5F2fKssy2HBf2fH2d7sHdaUjKk1c', 'testnet')
==> true
```

### Address information

`getAddressInfo(address)` parses the input address and returns information about its type and network.

If the input address is invalid, an exception will be thrown.

Valid witness addresses whose version and program length do not identify P2WPKH, P2WSH, or P2TR return `type: 'unknown'`. These addresses pass `validate`; applications that require a recognized payment type should also check `type`.

```js
getAddressInfo('17VZNX1SN5NtKa8UQFxwQbFeFc3iqRYhem')
==> {
  address: '17VZNX1SN5NtKa8UQFxwQbFeFc3iqRYhem',
  type: 'p2pkh',
  network: 'mainnet',
  bech32: false
}
```

### Networks

This library supports the following Bitcoin networks: `mainnet`, `testnet`, `regtest` and `signet`.

> `signet` addresses will always be recognized as `testnet` addresses.

> Non-bech32 `regtest` addresses will be recognized as `testnet` addresses.


#### Casting testnet addresses to regtest or signet


You can use the `options` parameter to cast `testnet` addresses to `regtest` or `signet`.

Other casting destinations are rejected, including in JavaScript: `getAddressInfo` throws and `validate` returns `false`.

```js
// Default - No casting
getAddressInfo('tb1qg3hss5p9g9jp0es5u5aaz3lszf6cvdggtmjarr');
==> {
  address: 'tb1qg3hss5p9g9jp0es5u5aaz3lszf6cvdggtmjarr',
  type: 'p2wpkh',
  network: 'testnet',
  bech32: true
}

// Cast testnet to signet
getAddressInfo('tb1qg3hss5p9g9jp0es5u5aaz3lszf6cvdggtmjarr', {
  castTestnetTo: 'signet'
})
==> {
  address: 'tb1qg3hss5p9g9jp0es5u5aaz3lszf6cvdggtmjarr',
  type: 'p2wpkh',
  network: 'signet',
  bech32: true
}

// Validating and casting
validate('tb1qg3hss5p9g9jp0es5u5aaz3lszf6cvdggtmjarr', 'signet', {
  castTestnetTo: 'signet'
})
==> true
```


### TypeScript support

If you're using TypeScript, the following types are provided with this library:

```ts
enum Network {
  mainnet = "mainnet",
  testnet = "testnet",
  regtest = "regtest",
  signet = "signet",
}

enum AddressType {
  p2pkh = 'p2pkh',
  p2sh = 'p2sh',
  p2wpkh = 'p2wpkh',
  p2wsh = 'p2wsh',
  p2tr = 'p2tr',
  unknown = 'unknown',
}

type AddressInfo = {
  bech32: boolean;
  network: Network;
  address: string;
  type: AddressType;
}
```

#### TypeScript usage

```ts
import { validate, getAddressInfo, Network, AddressInfo } from 'bitcoin-address-validation';

validate('36nGbqV7XCNf2xepCLAtRBaqzTcSjF4sv9', Network.mainnet);
==> true

const addressInfo: AddressInfo = getAddressInfo('2Mz8rxD6FgfbhpWf9Mde9gy6w8ZKE8cnesp');
addressInfo.network;

==> 'testnet'
```

## Development

Use Node.js 22 (22.12 or newer) or Node.js 24, with pnpm 10 or newer.

```bash
pnpm install
pnpm run ci
```

## Author

Rui Gomes  
https://ruigomes.me  

## License

The MIT License (MIT). Please see [LICENSE file](https://github.com/ruigomeseu/bitcoin-address-validation/blob/master/LICENSE.md) for more information.

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