ognus / wallet-address-validator

Useful library for validation of Bitcoin, Litecoin, Ethereum and other cryptocoin addresses
MIT License
262 stars 129 forks source link
altcoins bitcoin bitcoin-cash bitcoin-private cryptocurrency dash doge ethereum javascript litecoin monero nano nodejs ripple segwit validator vertcoin wallet zcash zclassic

wallet-address-validator

Simple wallet address validator for validating Bitcoin and other altcoins addresses in Node.js and browser.

Forked from ryanralph/altcoin-address.

File size is ~22 kB (minifed and gzipped).

Installation

NPM

npm install wallet-address-validator

Browser

<script src="https://github.com/ognus/wallet-address-validator/raw/master/wallet-address-validator.min.js"></script>

API

validate (address [, currency = 'bitcoin'[, networkType = 'prod']])
Parameters

Returns true if the address (string) is a valid wallet address for the crypto currency specified, see below for supported currencies.

Supported crypto currencies

Usage example

Node

var WAValidator = require('wallet-address-validator');

var valid = WAValidator.validate('1KFzzGtDdnq5hrwxXGjwVnKzRbvf8WVxck', 'BTC');
if(valid)
    console.log('This is a valid address');
else
    console.log('Address INVALID');

// This will log 'This is a valid address' to the console.
var WAValidator = require('wallet-address-validator');

var valid = WAValidator.validate('1KFzzGtDdnq5hrwxXGjwVnKzRbvf8WVxck', 'litecoin', 'testnet');
if(valid)
      console.log('This is a valid address');
else
      console.log('Address INVALID');

// As this is a invalid litecoin address 'Address INVALID' will be logged to console.

Browser

<script src="https://github.com/ognus/wallet-address-validator/raw/master/wallet-address-validator.min.js"></script>
// WAValidator is exposed as a global (window.WAValidator)
var valid = WAValidator.validate('1KFzzGtDdnq5hrwxXGjwVnKzRbvf8WVxck', 'bitcoin');
if(valid)
    alert('This is a valid address');
else
    alert('Address INVALID');

// This should show a pop up with text 'This is a valid address'.