4

How would one validate a bitcoin address using the bitcoinjs library? Or is there another way to do this via javascript?

Patoshi パトシ
  • 10,956
  • 18
  • 80
  • 151

1 Answers1

8

If you call

bitcoin.address.toOutputScript(address, bitcoin.networks.bitcoin)

It will throw an error if the address cannot be parsed as P2SH or P2PKH, or if the checksum is not valid. Replace the second argument with bitcoin.networks.testnet for testnet.

Nick ODell
  • 29,184
  • 11
  • 69
  • 129