How do you validate a bitcoin address using bitcoinjs library in javascript?

3

1

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

Patoshi パトシ

Posted 2017-04-12T21:38:59.443

Reputation: 8 911

1Do you mean for a website or app? Or do you just want to personally verify one?Marc Alexander 2017-04-12T22:23:54.583

for a website im working on. I have bitcoinjs library loaded, but not sure what function to call to check if a btc address is valid or not.Patoshi パトシ 2017-04-12T23:34:58.223

Answers

6

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

Posted 2017-04-12T21:38:59.443

Reputation: 26 536