← coderrocketfuel.com

Validate Bitcoin & Altcoin Wallet Address Types with Node.js

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):

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:

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:

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"
  • Bankex/BKX: "bankex" or "BKX"
  • BeaverCoin/BVC: "beavercoin" or "BVC"
  • Biocoin/BIO: "biocoin" or "BIO"
  • Bitcoin/BTC: "bitcoin" or "BTC"
  • BitcoinCash/BCH: "bitcoincash" or "BCH"
  • BitcoinGold/BTG: "bitcoingold" or "BTG"
  • BitcoinPrivate/BTCP: "bitcoinprivate" or "BTCP"
  • BitcoinZ/BTCZ: "bitcoinz" or "BTCZ"
  • Callisto/CLO: "callisto" or "CLO"
  • Dash: "dash" or "DASH"
  • Decred/DCR: "decred" or "DCR"
  • Digibyte/DGB: "digibyte" or "DGB"
  • Dogecoin/DOGE: "dogecoin" or "DOGE"
  • Ethereum/ETH: "ethereum" or "ETH"
  • EthereumClassic/ETH: "ethereumclassic" or "ETC"
  • EthereumZero/ETZ: "etherzero" or "ETZ"
  • Freicoin/FRC: "freicoin" or "FRC"
  • Garlicoin/GRLC: "garlicoin" or "GRLC"
  • Hush/HUSH: "hush" or "HUSH"
  • Komodo/KMD: "komodo" or "KMD"
  • Litecoin/LTC: "litecoin" or "LTC"
  • Megacoin/MEC: "megacoin" or "MEC"
  • Monero/XMR: "monero" or "XMR"
  • Namecoin/NMC: "namecoin" or "NMC"
  • Nano/NANO: "NEO" or "NEO"
  • NeoGas/GAS: "neogas" or "GAS"
  • Peercoin/PPCoin/PPC: "peercoin" or "PPC"
  • Primecoin/XPM: "primecoin" or "XPM"
  • Protoshares/PTS: "protoshares" or "PTS"
  • Qtum/QTUM: "qtum" or "QTUM"
  • Raiblocks/XRB: "raiblocks" or "XRB"
  • Ripple/XRP: "ripple" or "XRP"
  • Snowgem/SNG: "snowgem" or "SNG"
  • Vertcoin/VTC: "vertcoin" or "VTC"
  • Votecoin/VTC: "votecoin" or "VOT"
  • Zcash/ZEC: "zcash" or "ZEC"
  • Zclassic/ZCL: "zclassic" or "ZCL"
  • ZenCash/ZEN: "zencash" or "ZEN"

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