{"id":26220614,"url":"https://github.com/ruigomeseu/bitcoin-address-validation","last_synced_at":"2025-05-15T19:06:32.092Z","repository":{"id":45360034,"uuid":"136958183","full_name":"ruigomeseu/bitcoin-address-validation","owner":"ruigomeseu","description":"Validate Bitcoin addresses - P2WSH, P2WPKH, P2PKH, P2SH and P2TR","archived":false,"fork":false,"pushed_at":"2025-04-30T19:14:28.000Z","size":169,"stargazers_count":126,"open_issues_count":1,"forks_count":30,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-12T15:05:06.586Z","etag":null,"topics":["bitcoin","bitcoin-address","javascript","typescript","validation"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ruigomeseu.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-06-11T17:20:05.000Z","updated_at":"2025-04-30T08:35:23.000Z","dependencies_parsed_at":"2024-06-18T13:41:10.449Z","dependency_job_id":"7eeeac19-4a9d-4a14-86d2-2ed731e73756","html_url":"https://github.com/ruigomeseu/bitcoin-address-validation","commit_stats":{"total_commits":51,"total_committers":9,"mean_commits":5.666666666666667,"dds":"0.17647058823529416","last_synced_commit":"3419d23307ddb0a86e44e1430a678e126b98bf7d"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruigomeseu%2Fbitcoin-address-validation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruigomeseu%2Fbitcoin-address-validation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruigomeseu%2Fbitcoin-address-validation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruigomeseu%2Fbitcoin-address-validation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ruigomeseu","download_url":"https://codeload.github.com/ruigomeseu/bitcoin-address-validation/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254404357,"owners_count":22065641,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bitcoin","bitcoin-address","javascript","typescript","validation"],"created_at":"2025-03-12T15:18:28.466Z","updated_at":"2025-05-15T19:06:32.070Z","avatar_url":"https://github.com/ruigomeseu.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bitcoin-address-validation\n\n[![npm version](https://badge.fury.io/js/bitcoin-address-validation.svg)](https://www.npmjs.com/package/bitcoin-address-validation)\n[![npm](https://img.shields.io/npm/dt/bitcoin-address-validation.svg)](https://www.npmjs.com/package/bitcoin-address-validation)\n[![Twitter Follow](https://img.shields.io/twitter/follow/8bitgomes.svg?style=social)](https://twitter.com/8bitgomes)\n\nValidate Bitcoin addresses - P2WSH, P2WPKH, P2PKH, P2SH and P2TR.\n\n```js\nvalidate('bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4');\n==\u003e true\n\ngetAddressInfo('bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4');\n==\u003e { \n  bech32: true,\n  network: 'mainnet',\n  address: 'bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4',\n  type: 'p2wpkh'\n}\n```\n\n## Installation\nAdd `bitcoin-address-validation` to your Javascript project dependencies using Yarn:\n```bash\nyarn add bitcoin-address-validation\n```\nOr NPM:\n```bash\nnpm install bitcoin-address-validation --save\n```\n\n## Usage\n\n### Importing\nImport using ES6:\n\n```js\nimport { validate, getAddressInfo } from 'bitcoin-address-validation';\n```\n\nOr AMD:\n\n```js\nconst { validate, getAddressInfo } = require('bitcoin-address-validation');\n```\n\n### Validating addresses\n\n`validate(address)` returns `true` for valid Bitcoin addresses or `false` for invalid Bitcoin addresses.\n\n```js\nvalidate('17VZNX1SN5NtKa8UQFxwQbFeFc3iqRYhem')\n==\u003e true\n\nvalidate('invalid')\n==\u003e false\n```\n\n#### Network validation\n\n`validate(address, network)` allows you to validate whether an address is valid and belongs to `network`.\n\n```js\nvalidate('36bJ4iqZbNevh9b9kzaMEkXb28Gpqrv2bd', 'mainnet')\n==\u003e true\n\nvalidate('36bJ4iqZbNevh9b9kzaMEkXb28Gpqrv2bd', 'testnet')\n==\u003e false\n\nvalidate('2N4RsPe5F2fKssy2HBf2fH2d7sHdaUjKk1c', 'testnet')\n==\u003e true\n```\n\n### Address information\n\n`getAddressInfo(address)` parses the input address and returns information about its type and network.\n\nIf the input address is invalid, an exception will be thrown.\n\n```js\ngetAddressInfo('17VZNX1SN5NtKa8UQFxwQbFeFc3iqRYhem')\n==\u003e {\n  address: '17VZNX1SN5NtKa8UQFxwQbFeFc3iqRYhem',\n  type: 'p2pkh',\n  network: 'mainnet',\n  bech32: false\n}\n```\n\n### Networks\n\nThis library supports the following Bitcoin networks: `mainnet`, `testnet`, `regtest` and `signet`.\n\n\u003e `signet` addresses will always be recognized as `testnet` addresses.\n\n\u003e Non-bech32 `regtest` addresses will be recognized as `testnet` addresses.\n\n\n#### Casting testnet addresses to regtest or signet\n\n\nYou can use the `options` parameter to cast `testnet` addresses to `regtest` or `signet`.\n\n```js\n// Default - No casting\ngetAddressInfo('tb1qg3hss5p9g9jp0es5u5aaz3lszf6cvdggtmjarr');\n==\u003e {\n  address: 'tb1qg3hss5p9g9jp0es5u5aaz3lszf6cvdggtmjarr',\n  type: 'p2wpkh',\n  network: 'testnet',\n  bech32: true\n}\n\n// Cast testnet to signet\ngetAddressInfo('tb1qg3hss5p9g9jp0es5u5aaz3lszf6cvdggtmjarr', {\n  castTestnetTo: 'signet'\n})\n==\u003e {\n  address: 'tb1qg3hss5p9g9jp0es5u5aaz3lszf6cvdggtmjarr',\n  type: 'p2wpkh',\n  network: 'signet',\n  bech32: true\n}\n\n// Validating and casting\nvalidate('tb1qg3hss5p9g9jp0es5u5aaz3lszf6cvdggtmjarr', 'signet', {\n  castTestnetTo: 'signet'\n})\n==\u003e true\n```\n\n\n### TypeScript support\n\nIf you're using TypeScript, the following types are provided with this library:\n\n```ts\nenum Network {\n  mainnet = \"mainnet\",\n  testnet = \"testnet\",\n  regtest = \"regtest\",\n  signet = \"signet\",\n}\n\nenum AddressType {\n  p2pkh = 'p2pkh',\n  p2sh = 'p2sh',\n  p2wpkh = 'p2wpkh',\n  p2wsh = 'p2wsh',\n  p2tr = 'p2tr',\n}\n\ntype AddressInfo = {\n  bech32: boolean;\n  network: Network;\n  address: string;\n  type: AddressType;\n}\n```\n\n#### TypeScript usage\n\n```ts\nimport { validate, getAddressInfo, Network, AddressInfo } from 'bitcoin-address-validation';\n\nvalidate('36nGbqV7XCNf2xepCLAtRBaqzTcSjF4sv9', Network.mainnet);\n==\u003e true\n\nconst addressInfo: AddressInfo = getAddressInfo('2Mz8rxD6FgfbhpWf9Mde9gy6w8ZKE8cnesp');\naddressInfo.network;\n\n==\u003e 'testnet'\n```\n\n## Author\n\nRui Gomes  \nhttps://ruigomes.me  \n\n## License\n\nThe MIT License (MIT). Please see [LICENSE file](https://github.com/ruigomeseu/bitcoin-address-validation/blob/master/LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fruigomeseu%2Fbitcoin-address-validation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fruigomeseu%2Fbitcoin-address-validation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fruigomeseu%2Fbitcoin-address-validation/lists"}