|
| 1 | +--- |
| 2 | +title: btcAddress |
| 3 | +description: Creates a Bitcoin address validation action. |
| 4 | +source: /actions/btcAddress/btcAddress.ts |
| 5 | +contributors: |
| 6 | + - shuaixr |
| 7 | +--- |
| 8 | + |
| 9 | +import { ApiList, Link, Property } from '~/components'; |
| 10 | +import { properties } from './properties'; |
| 11 | + |
| 12 | +# btcAddress |
| 13 | + |
| 14 | +Creates a [Bitcoin address](https://en.bitcoin.it/wiki/Address) validation action. |
| 15 | + |
| 16 | +> This action accepts both legacy Base58Check addresses and native SegWit Bech32 or Bech32m addresses. If you only need one format, use <Link href="../btcAddressBase58/">`btcAddressBase58`</Link> or <Link href="../btcAddressBech32/">`btcAddressBech32`</Link> instead. |
| 17 | +
|
| 18 | +```ts |
| 19 | +const Action = v.btcAddress<TInput, TMessage>(message); |
| 20 | +``` |
| 21 | + |
| 22 | +## Generics |
| 23 | + |
| 24 | +- `TInput` <Property {...properties.TInput} /> |
| 25 | +- `TMessage` <Property {...properties.TMessage} /> |
| 26 | + |
| 27 | +## Parameters |
| 28 | + |
| 29 | +- `message` <Property {...properties.message} /> |
| 30 | + |
| 31 | +### Explanation |
| 32 | + |
| 33 | +With `btcAddress` you can validate common Bitcoin receive addresses for mainnet and testnet. It combines the Base58Check rules used by legacy `1...`, `3...`, `m...`, `n...`, and `2...` addresses with the Bech32 and Bech32m rules used by native SegWit `bc1...` and `tb1...` addresses. |
| 34 | + |
| 35 | +The Base58Check branch follows Bitcoin's version-byte and double-SHA-256 checksum format and uses `@noble/hashes` for SHA-256. The Bech32 branch follows BIP-0173 and BIP-0350 and does not need SHA-256. Because this action accepts both address families, importing it includes both validation paths. |
| 36 | + |
| 37 | +This action validates address format, network prefix, witness rules, and checksum. It does not check balances, transaction history, ownership, or whether an address is safe to send funds to. |
| 38 | + |
| 39 | +## Returns |
| 40 | + |
| 41 | +- `Action` <Property {...properties.Action} /> |
| 42 | + |
| 43 | +## Examples |
| 44 | + |
| 45 | +The following examples show how `btcAddress` can be used. |
| 46 | + |
| 47 | +### Bitcoin address schema |
| 48 | + |
| 49 | +Schema to validate a Bitcoin address. |
| 50 | + |
| 51 | +```ts |
| 52 | +const BitcoinAddressSchema = v.pipe( |
| 53 | + v.string(), |
| 54 | + v.btcAddress('The Bitcoin address is invalid.') |
| 55 | +); |
| 56 | +``` |
| 57 | + |
| 58 | +## Related |
| 59 | + |
| 60 | +The following APIs can be combined with `btcAddress`. |
| 61 | + |
| 62 | +### Actions |
| 63 | + |
| 64 | +<ApiList items={['btcAddressBase58', 'btcAddressBech32']} /> |
| 65 | + |
| 66 | +### Schemas |
| 67 | + |
| 68 | +<ApiList items={['any', 'custom', 'string']} /> |
| 69 | + |
| 70 | +### Methods |
| 71 | + |
| 72 | +<ApiList items={['pipe']} /> |
| 73 | + |
| 74 | +### Utils |
| 75 | + |
| 76 | +<ApiList items={['isOfKind', 'isOfType']} /> |
0 commit comments