multicoin-address-validator README

The project's README from github.com/Nonco-Organization/multicoin-address-validator. As one markdown file: README.md.

wallet-address-validator

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

Build Status

Forked from ryanralph/altcoin-address.

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

Installation

NPM

npm install multicoin-address-validator

Browser

<script src="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('multicoin-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('multicoin-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.
var WAValidator = require('multicoin-address-validator');

var currency = WAValidator.findCurrency('xrp');
if(currency)
      console.log('This currency exists');
else
      console.log('Currency INVALID');

// As this is a valid currency symbol 'This currency exists' will be logged to console.
var WAValidator = require('multicoin-address-validator');

var currency = WAValidator.findCurrency('random');
if(currency)
      console.log('This currency exists');
else
      console.log('Currency INVALID');

// As this is not a valid currency symbol 'Currency INVALID' will be logged to console.

Browser

<script src="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'.

multicoin-address-validator (Nonco-Organization/multicoin-address-validator)

Searching Database…

这是什么?一个 JavaScript 库,用于验证 Bitcoin、Litecoin、Ethereum 以及 100 多种其他加密货币的钱包地址。
它是框架还是库?它是一个可导入你自己代码的轻量级库,只暴露一个 validate 函数,不是独立应用。
我怎么把它加到项目里?通过 NPM 安装,或直接在网页中引入浏览器构建版本。
使用它需要任何 API 密钥或网络访问吗?不需要,它是一个纯验证库,在本地检查地址格式和校验和,不会调用任何区块链或外部服务。
验证只检查格式,还是会核实地址在链上真实存在?它只验证给定币种的地址格式/校验和;不会检查该地址在区块链上是否真的在使用或有余额。
它只支持类 Bitcoin 的币种,还是也支持 Ethereum 风格的地址?它同时支持 Bitcoin 风格的 UTXO 币种和 Ethereum 风格的账户地址,还有许多共用 Ethereum 地址格式的 ERC-20 代币。
validate 函数是怎么工作的?调用 validate(address, currency, networkType),其中 currency 默认为 'bitcoin',networkType 可以是 'prod'、'testnet' 或 'both';如果地址对该币种有效则返回 true。
我能验证测试网地址吗?可以,把 'testnet' 作为 networkType 参数传入,就会强制使用测试网地址规则,而不是生产主网地址。
这个项目是怎么来的?它是 ryanralph/altcoin-address 的一个分叉,扩展后支持了更多加密货币。
支持多少种加密货币?README 列出了 100 多种受支持的币和代币,可通过全名或 ticker 简称来指定(例如 'bitcoin' 或 'btc')。
Size
1.6 MB
Stars
230
Updated
CommitApr 29
Age
10d
Commits · 90 Days