Introduction

Cryptocurrency has done a lot to change the landscape of money and freedom on the internet. But adoption will still take lots more time and the usability of crypto is not 100% friendly to new users and adopters.

One of the scary parts of using cryptocurrency is sending currency from one wallet address to another can be incredibly unnerving. And this is especially true when dealing with large sums of currency. Wallet addresses are long strings of numbers and letters that are hard to understand and easy to mess up.

And all of the different types of cryptocurrencies have addresses that look very similar. So, a way to help with that problem is to verify that the address you're working with is the type of coin you think it is.

To do this programmatically in Node.js, there is a great NPM package called wallet-address-validator that will make this super easy.

You can install the package with this command (you can also use yarn add ):

Command Copy npm install wallet-address-validator

With the NPM package installed, you're ready to work through the examples below.

Table Of Contents

Bitcoin Example

For demonstration purposes, let's pretend you're sending Bitcoin from one address to another. But you want to verify that the receiving address is a valid Bitcoin address.

The Node.js code would look like below:

Node.js Copy const WAValidator = require("wallet-address-validator") const valid = WAValidator.validate("1KFzzGtDdnq5hrwxXGjwVnKzRbvf8WVxck", "BTC") console.log(valid) // => true

We give the WAValidator.validate() function both the address we want to validate and the type of cryptocurrency it's supposed to be ( "BTC" in this case). And it returns as either a true or false value.

Ethereum Example

Let's try another example with an Ethereum address.

Below is what the code would look like:

Node.js Copy const WAValidator = require("wallet-address-validator") const valid = WAValidator.validate("0x819b8c28b340dd33e32282cf586679afc57d4422", "ethereum") console.log(valid) // => true

This example is very similar to the Bitcoin one from before. But notice that we used the full name of the cryptocurrency ( "ethereum" ) instead of the coin's symbol ( "ETH" ). Both will work when given to the WAValidator.validate() function.

Full List of Supported Cryptocurrencies

The npm package supports many more types of cryptocurrencies beyond just Bitcoin and Ethereum. Below is the full list of coins and the accepted strings to use in the validation function:

Auroracoin/AUR : "auroracoin" or "AUR"

: or Bankex/BKX : "bankex" or "BKX"

: or BeaverCoin/BVC : "beavercoin" or "BVC"

: or Biocoin/BIO : "biocoin" or "BIO"

: or Bitcoin/BTC : "bitcoin" or "BTC"

: or BitcoinCash/BCH : "bitcoincash" or "BCH"

: or BitcoinGold/BTG : "bitcoingold" or "BTG"

: or BitcoinPrivate/BTCP : "bitcoinprivate" or "BTCP"

: or BitcoinZ/BTCZ : "bitcoinz" or "BTCZ"

: or Callisto/CLO : "callisto" or "CLO"

: or Dash : "dash" or DASH

: or Decred/DCR : "decred" or "DCR"

: or Digibyte/DGB : "digibyte" or "DGB"

: or Dogecoin/DOGE : "dogecoin" or "DOGE"

: or Ethereum/ETH : "ethereum" or "ETH"

: or EthereumClassic/ETH : "ethereumclassic" or "ETC"

: or EthereumZero/ETZ : "etherzero" or "ETZ"

: or Freicoin/FRC : "freicoin" or "FRC"

: or Garlicoin/GRLC : "garlicoin" or "GRLC"

: or Hush/HUSH : "hush" or "HUSH"

: or Komodo/KMD : "komodo" or "KMD"

: or Litecoin/LTC : "litecoin" or "LTC"

: or Megacoin/MEC : "megacoin" or "MEC"

: or Monero/XMR : "monero" or "XMR"

: or Namecoin/NMC : "namecoin" or "NMC"

: or Nano/NANO : "NEO" or "NEO"

: or NeoGas/GAS : "neogas" or "GAS"

: or Peercoin/PPCoin/PPC : "peercoin" or "PPC"

: or Primecoin/XPM : "primecoin" or "XPM"

: or Protoshares/PTS : "protoshares" or "PTS"

: or Qtum/QTUM : "qtum" or "QTUM"

: or Raiblocks/XRB : "raiblocks" or "XRB"

: or Ripple/XRP : "ripple" or "XRP"

: or Snowgem/SNG : "snowgem" or "SNG"

: or Vertcoin/VTC : "vertcoin" or "VTC"

: or Votecoin/VTC : "votecoin" or "VOT"

: or Zcash/ZEC : "zcash" or "ZEC"

: or Zclassic/ZCL : "zclassic" or "ZCL"

: or ZenCash/ZEN: "zencash" or "ZEN"

Conclusion

There you have it, you now know how to validate cryptocurrency addresses using Node.js!

Thanks for reading and happy coding!