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:
- If
opts.chainType is provided, the function attempts to use the validator associated with that chainType first. - 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' });