How would one validate a bitcoin address using the bitcoinjs library? Or is there another way to do this via javascript?
-
1Do you mean for a website or app? Or do you just want to personally verify one?– Marc AlexanderApr 12, 2017 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, 2017 at 23:34
1 Answer
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.