4

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

  • 1
    Do you mean for a website or app? Or do you just want to personally verify one? – Marc Alexander Apr 12 '17 at 22:23
  • 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 パトシ Apr 12 '17 at 23:34
7

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.