Withdraw

Asset Withdrawal Networks

This table details the networks through which each asset can be withdrawn, along with the unique symbols used on each network. This information is crucial for identifying where to store assets for accessibility and ease of transactions. Knowing both the network and its associated asset symbol aids in managing withdrawals and transfers across different blockchain platforms.

The symbolNetworks object is a structured representation of various cryptocurrencies and their available networks for withdrawal purposes. Each key in this object represents a cryptocurrency symbol for API, and the associated value is an array of objects, each describing a network where the cryptocurrency can be withdrawn.

const symbolNetworks = {
    "ETH": [
        { Network: "ETH", Label: "Ethereum Mainnet", Symbol: "ETH" },
        { Network: "OPT", Label: "Optimism Mainnet", Symbol: "OPT-ETH" }
    ],
    "USDT": [
        { Network: "ETH", Label: "Ethereum Mainnet", Symbol: "USDT" },
        { Network: "BSC", Label: "Binance Smartchain", Symbol: "BSC-USD" },
        { Network: "OPT", Label: "Optimism Mainnet", Symbol: "OPT-USD" }
    ],
    "BNB": [
        { Network: "BSC", Label: "Binance Smartchain", Symbol: "BNB" }
    ]
};

Validate Address

This document explains the functionality of the validateAddress function which is designed to validate addresses for various cryptocurrencies like Ethereum, Bitcoin, Litecoin, and others based on their unique standards and requirements.

Function Overview

The validateAddress function is crucial for ensuring that the cryptocurrency addresses provided by users are valid according to the specific rules and formats of each cryptocurrency network. Below is the JavaScript code which can be used in your project to validate addresses.

JavaScript Function Code

import { keccak256 } from 'js-sha3';

// Optimized helper function to check if an address is valid based on symbol
const mnemonicSymbols = new Set(['ETH', 'BNB', 'BSC-USD', 'USDT', 'OPT-ETH', 'OPT-USD', 'BUSD']);

export const validateAddress = (address, symbol) => {
    if (mnemonicSymbols.has(symbol)) {
        return isValidMnemonicAddress(address);
    }
    
    const symbolValidationMap = {
        'BTC': isValidBTCAddress,
        'LTC': isValidLTCAddress
    };
    
    const validateFn = symbolValidationMap[symbol];
    return validateFn ? validateFn(address) : false;
};

// Validates if the Ethereum address is valid (using checksum if needed)
function isValidMnemonicAddress(address) {
    const ethAddressRegex = /^0x[a-fA-F0-9]{40}$/;
    if (!ethAddressRegex.test(address)) return false;
    if (address === address.toLowerCase() || address === address.toUpperCase()) return true;
    return isChecksumAddress(address);
}

// Validates the checksum of an Ethereum address
function isChecksumAddress(address) {
    const addressWithoutPrefix = address.slice(2).toLowerCase();
    const addressHash = keccak256(addressWithoutPrefix);
    
    for (let i = 0; i < 40; i++) {
        const hashCharDecimal = parseInt(addressHash[i], 16);
        const addressChar = addressWithoutPrefix[i];
        const isUpper = address[i + 2] === addressChar.toUpperCase();
        const isLower = address[i + 2] === addressChar.toLowerCase();
        
        if ((hashCharDecimal > 7 && !isUpper) || (hashCharDecimal <= 7 && !isLower)) return false;
    }
    
    return true;
}

// Validates if a Bitcoin address is valid based on the given regex patterns
function isValidBTCAddress(address) {
    const p2pkhRegex = /^[1][1-9A-HJ-NP-Za-km-z]{25,34}$/;
    const p2shRegex = /^[3][1-9A-HJ-NP-Za-km-z]{25,34}$/;
    const bech32Regex = /^bc1[a-z0-9]{25,39}$/;
    
    return p2pkhRegex.test(address) || p2shRegex.test(address) || bech32Regex.test(address);
}

// Validates if a Litecoin address is valid based on the given regex patterns
function isValidLTCAddress(address) {
    const legacyRegex = /^[LM3][a-km-zA-HJ-NP-Z1-9]{26,33}$/;
    const segwitRegex = /^ltc1[qprz][a-z0-9]{38,60}$/;
    
    return legacyRegex.test(address) || segwitRegex.test(address);
}

Was this page helpful?