multicoin-address-validator

repository·master·Indexed 41 days ago

https://github.com/christsim/multicoin-address-validator

A wallet address validator for Bitcoin and various altcoins, compatible with Node.js and browser environments. Version 0.5.26 provides methods to validate addresses using currency names or symbols, check for supported currencies via findCurrency(), and handle unknown tokens using chainType mappings.

Tokens
4.6K
Snippets
9
Records
9
Agent score
50%

What's inside multicoin-address-validator

  1. Validate addresses for unknown tokens using chainType

    master

    If you are validating a token that isn't explicitly listed in the supported currencies, you can pass a chainType in the options object. If the currency name is not found, the validator will fall back to the validator for that specific chainType (e.g., 'ethereum').

    var WAValidator = require('multicoin-address-validator');
    
    var valid = WAValidator.validate('0xdbF03B407c01E7cD3CBea99509d93f8DDDC8C6FB', 'UNKNOWN TOKEN', {chainType: 'ethereum'});
    if(valid)
    	console.log('This is a valid address');
    else
    	console.log('Address INVALID');
  2. Use findCurrency() to check for supported currencies

    master

    The findCurrency method allows you to check if a specific currency name or symbol is supported by the library.

    var WAValidator = require('multicoin-address-validator');
    
    var currency = WAValidator.findCurrency('xrp');
    if(currency)
          console.log('This currency exists');
    else
          console.log('Currency INVALID');
  3. Use the validate() method

    master

    The validate method checks if a given string is a valid wallet address for a specific currency and network type. It returns true if valid, otherwise false.

    // Signature:
    // validate (address [, currency = 'bitcoin'[, networkType = 'prod']])
    
    // Parameters:
    // * address - Wallet address to validate.
    // * currency - Optional. Currency name or symbol, e.g. 'bitcoin' (default), 'litecoin' or 'LTC'
    // * networkType - Optional. Use 'prod' (default) to enforce standard address, 'testnet' to enforce testnet address and 'both' to enforce nothing.
    // * chainType - Optional. Specify the chainType, eg 'ethereum'. If the given currency is not found but the chainType is, the validator for that chainType will be used.
  4. Reference: Supported crypto currencies

    master

    The validator supports a wide range of currencies using either their full name or their symbol. Examples include:

    • Bitcoin: 'Bitcoin' or 'btc'
    • Ethereum: 'Ethereum' or 'eth'
    • Litecoin: 'LiteCoin' or 'ltc'
    • Solana: 'Solana' or 'sol'
    • Ripple: 'Ripple' or 'xrp'

    (See the full list in the documentation for all supported symbols and names.)

    0x/zrx `'0x'` or `'zrx'
    Aave Coin/aave `'Aave Coin'` or `'aave'
    Algorand/algo `'Algorand'` or `'algo'
    Apecoin/ape `'Apecoin'` or `'ape'
    API3/api3 `'API3'` or `'api3'
    Aptos/apt `'Aptos'` or `'apt'
    Aragon/ant `'Aragon'` or `'ant'
    Arbitrum/arb `'Arbitrum'` or `'arb'
    Augur/rep `'Augur'` or `'rep'
    AugurV2/repv2 `'AugurV2'` or `'repv2'
    AuroraCoin/aur `'AuroraCoin'` or `'aur'
    Avalanche/avax `'Avalanche'` or `'avax'
    Axie Infinity/axs `'Axie Infinity'` or `'axs'
    Bancor/bnt `'Bancor'` or `'bnt'
    Band Protocol/band `'Band Protocol'` or `'band'
    Bankex/bkx `'Bankex'` or `'bkx'
    Basic Attention Token/bat `'Basic Attention Token'` or `'bat'
    BeaverCoin/bvc `'BeaverCoin'` or `'bvc'
    Berachain/bera `'Berachain'` or `'bera'
    Biconomy/bico `'Biconomy'` or `'bico'
    Binance/bnb `'Binance'` or `'bnb'
    BinanceSmartChain/bnb `'BinanceSmartChain'` or `'bnb'
    BioCoin/bio `'BioCoin'` or `'bio'
    Bitcoin/btc `'Bitcoin'` or `'btc'
    Bitcoin SV/bsv `'Bitcoin SV'` or `'bsv'
    BitcoinCash/bch `'BitcoinCash'` or `'bch'
    BitcoinGold/btg `'BitcoinGold'` or `'btg'
    BitcoinPrivate/btcp `'BitcoinPrivate'` or `'btcp'
    BitcoinZ/btcz `'BitcoinZ'` or `'btcz'
    BlockTrade/btt `'BlockTrade'` or `'btt'
    Blur/blur `'Blur'` or `'blur'
    Bonk/bonk `'Bonk'` or `'bonk'
    BTU Protocol/btu `'BTU Protocol'` or `'btu'
    Callisto/clo `'Callisto'` or `'clo'
    Cardano/ada `'Cardano'` or `'ada'
    Celo/celo `'Celo'` or `'celo'
    Chainlink/link `'Chainlink'` or `'link'
    Chiliz/chz `'Chiliz'` or `'chz'
    Civic/cvc `'Civic'` or `'cvc'
    Compound/comp `'Compound'` or `'comp'
    Cred/lba `'Cred'` or `'lba'
    Crypto.com Coin/cro `'Crypto.com Coin'` or `'cro'
    Curve DAO/crv `'Curve DAO'` or `'crv'
    CUSD/cusd `'CUSD'` or `'cusd'
    Dash/dash `'Dash'` or `'dash'
    Decentraland/mana `'Decentraland'` or `'mana'
    Decred/dcr `'Decred'` or `'dcr'
    DigiByte/dgb `'DigiByte'` or `'dgb'
    District0x/dnt `'District0x'` or `'dnt'
    DogeCoin/doge `'DogeCoin'` or `'doge'
    Enjin Coin/enj `'Enjin Coin'` or `'enj'
    EOS/eos `'EOS'` or `'eos'
    Ethereum/eth `'Ethereum'` or `'eth'
    Ethereum Name Service/ens `'Ethereum Name Service'` or `'ens'
    EthereumClassic/etc `'EthereumClassic'` or `'etc'
    EthereumPow/ethw `'EthereumPow'` or `'ethw'
    EtherZero/etz `'EtherZero'` or `'etz'
    Expanse/exp `'Expanse'` or `'exp'
    Fetch.ai/fet `'Fetch.ai'` or `'fet'
    FirmaChain/fct `'FirmaChain'` or `'fct'
    Flare/flr `'Flare'` or `'flr'
    FreiCoin/frc `'FreiCoin'` or `'frc'
    GameCredits/game `'GameCredits'` or `'game'
    GarliCoin/grlc `'GarliCoin'` or `'grlc'
    Gnosis/gno `'Gnosis'` or `'gno'
    Golem/glm `'Golem'` or `'glm'
    Golem (GNT)/gnt `'Golem (GNT)'` or `'gnt'
    Hashflow/hft `'Hashflow'` or `'hft'
    Hedera/hbar `'Hedera'` or `'hbar'
    HedgeTrade/hedg `'HedgeTrade'` or `'hedg'
    Hush/hush `'Hush'` or `'hush'
    HyperSpace/xsc `'HyperSpace'` or `'xsc'
    iExec RLC/rlc `'iExec RLC'` or `'rlc'
    Illuvium/ilv `'Illuvium'` or `'ilv'
    Immutable/imx `'Immutable'` or `'imx'
    Injective/inj `'Injective'` or `'inj'
    Komodo/kmd `'Komodo'` or `'kmd'
    LBRY Credits/lbc `'LBRY Credits'` or `'lbc'
    Lido DAO Token/ldo `'Lido DAO Token'` or `'ldo'
    LiteCoin/ltc `'LiteCoin'` or `'ltc'
    loki/loki `'loki'` or `'loki'
    Loom Network/loom `'Loom Network'` or `'loom'
    Magic/magic `'Magic'` or `'magic'
    Maker/mkr `'Maker'` or `'mkr'
    Marlin/pond `'Marlin'` or `'pond'
    Mask Network/mask `'Mask Network'` or `'mask'
    Matchpool/gup `'Matchpool'` or `'gup'
    Matic/matic `'Matic'` or `'matic'
    MegaCoin/mec `'MegaCoin'` or `'mec'
    Melon/mln `'Melon'` or `'mln'
    Metal/mtl `'Metal'` or `'mtl'
    Monero/xmr `'Monero'` or `'xmr'
    Multi-collateral DAI/dai `'Multi-collateral DAI'` or `'dai'
    NameCoin/nmc `'NameCoin'` or `'nmc'
    Nano/nano `'Nano'` or `'nano'
    Nem/xem `'Nem'` or `'xem'
    Neo/neo `'Neo'` or `'neo'
    NeoGas/gas `'NeoGas'` or `'gas'
    Numeraire/nmr `'Numeraire'` or `'nmr'
    Ocean Protocol/ocean `'Ocean Protocol'` or `'ocean'
    Odyssey/ocn `'Odyssey'` or `'ocn'
    OmiseGO/omg `'OmiseGO'` or `'omg'
    Onyx Protocol/xcn `'Onyx Protocol'` or `'xcn'
    Optimism/op `'Optimism'` or `'op'
    Origin Protocol/ogn `'Origin Protocol'` or `'ogn'
    Paxos/pax `'Paxos'` or `'pax'
    PayPal USD/pyusd `'PayPal USD'` or `'pyusd'
    PeerCoin/ppc `'PeerCoin'` or `'ppc'
    PIVX/pivx `'PIVX'` or `'pivx'
    Polkadot/dot `'Polkadot'` or `'dot'
    Polymath/poly `'Polymath'` or `'poly'
    PrimeCoin/xpm `'PrimeCoin'` or `'xpm'
    ProtoShares/pts `'ProtoShares'` or `'pts'
    Qtum/qtum `'Qtum'` or `'qtum'
    Quant/qnt `'Quant'` or `'qnt'
    Quantum Resistant Ledger/qrl `'Quantum Resistant Ledger'` or `'qrl'
    RaiBlocks/xrb `'RaiBlocks'` or `'xrb'
    Ripio Credit Network/rcn `'Ripio Credit Network'` or `'rcn'
    Ripple/xrp `'Ripple'` or `'xrp'
    Salt/salt `'Salt'` or `'salt'
    Serve/serv `'Serve'` or `'serv'
    Siacoin/sc `'Siacoin'` or `'sc'
    Skale/skl `'Skale'` or `'skl'
    SnowGem/sng `'SnowGem'` or `'sng'
    Solana/sol `'Solana'` or `'sol'
    SolarCoin/slr `'SolarCoin'` or `'slr'
    SOLVE/solve `'SOLVE'` or `'solve'
    Sonic/s `'Sonic'` or `'s'
    Spendcoin/spnd `'Spendcoin'` or `'spnd'
    Status/snt `'Status'` or `'snt'
    Stellar/xlm `'Stellar'` or `'xlm'
    Storj/storj `'Storj'` or `'storj'
    Storm/storm `'Storm'` or `'storm'
    StormX/stmx `'StormX'` or `'stmx'
    Story/ip `'Story'` or `'ip'
    SuperVerse/super `'SuperVerse'` or `'super'
    Swarm City/swt `'Swarm City'` or `'swt'
    Synthetix Network/snx `'Synthetix Network'` or `'snx'
    Tap/xtp `'Tap'` or `'xtp'
    Tellor/trb `'Tellor'` or `'trb'
    TEMCO/temco `'TEMCO'` or `'temco'
    TenX/pay `'TenX'` or `'pay'
    Tether/usdt `'Tether'` or `'usdt'
    Tezos/xtz `'Tezos'` or `'xtz'
    The Graph/grt `'The Graph'` or `'grt'
    The Sandbox/sand `'The Sandbox'` or `'sand'
    Tron/trx `'Tron'` or `'trx'
    TrueUSD/tusd `'TrueUSD'` or `'tusd'
    Unifi Protocol DAO/unfi `'Unifi Protocol DAO'` or `'unfi'
    Uniswap Coin/uni `'Uniswap Coin'` or `'uni'
    USD Coin/usdc `'USD Coin'` or `'usdc'
    VeChain/vet `'VeChain'` or `'vet'
    VertCoin/vtc `'VertCoin'` or `'vtc'
    Viberate/vib `'Viberate'` or `'vib'
    VoteCoin/vot `'VoteCoin'` or `'vot'
    Vulcan Forged PYR/pyr `'Vulcan Forged PYR'` or `'pyr'
    Waves/waves `'Waves'` or `'waves'
    Wings/wings `'Wings'` or `'wings'
    Yearn.finance/yfi `'Yearn.finance'` or `'yfi'
    ZCash/zec `'ZCash'` or `'zec'
    ZClassic/zcl `'ZClassic'` or `'zcl'
    ZenCash/zen `'ZenCash'` or `'zen'`
  5. Validate a cryptocurrency address with validate()

    master

    The validate function checks if a given address is valid for a specific currency. It supports validation by currency name/symbol and can be specialized using chainType or networkType via the opts argument.

    Parameters:

    • address (string): The wallet address to validate.
    • currencyNameOrSymbol (string): The name or symbol of the cryptocurrency (e.g., 'bitcoin', 'btc'). If omitted, it defaults to 'bitcoin'.
    • opts (object | string):
      • If an object, it can contain chainType (string) to use a specific chain validator, or other configuration passed to the underlying validator.
      • If a string, it is treated as the networkType (e.g., 'mainnet', 'testnet').

    Validation Logic Priority:

    1. If opts.chainType is provided, the function attempts to use the validator associated with that chainType first.
    2. If no chainType match is found or provided, it falls back to the validator defined for the specific currency.

    Errors: Throws an error if no validator is found for the specified currency.

    const validator = require('multicoin-address-validator');
    
    // Validate using network type as a string
    const isValid = validator.validate('1A1zP1eP5QGefi2DMPTfZbS5E89r688666', 'bitcoin', 'mainnet');
    
    // Validate using an options object with chainType
    const isValidChain = validator.validate('address', 'bitcoin', { chainType: 'segwit' });