Skip to content

Getting Started

Samarth Patel edited this page Jan 27, 2026 · 1 revision

Getting Started with validator0x

Complete guide to installing and using validator0x in your project.

📦 Installation

Install via npm:

npm install validator0x

Or using yarn:

yarn add validator0x

Or using pnpm:

pnpm add validator0x

🎯 Basic Usage

Validating an Address

import { validateAddress } from 'validator0x';

// Ethereum address
const ethResult = validateAddress(
  '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb',
  'ethereum'
);

console.log(ethResult);
// {
//   valid: true,
//   blockchain: 'ethereum',
//   details: {
//     format: 'eip55',
//     network: 'mainnet',
//     checksum: true
//   }
// }

// Solana address
const solResult = validateAddress(
  'DYw8jCTfwHNRJhhmFcbXvVDTqWMEVFBX6ZKUmG5CNSKK',
  'solana'
);

// Bitcoin address
const btcResult = validateAddress(
  'bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq',
  'bitcoin'
);

Formatting Addresses

import { formatAddress } from 'validator0x';

// Apply EIP-55 checksum
const formatted = formatAddress(
  '0x742d35cc6634c0532925a3b844bc9e7595f0beb',
  'ethereum',
  { checksum: true }
);
// Returns: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb'

// Shorten for UI display
const shortened = formatAddress(
  '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb',
  'ethereum',
  { shorten: true, shortenLength: 6 }
);
// Returns: '0x742d...5f0bEb'

Detecting Blockchain

import { detectBlockchain } from 'validator0x';

const chains = detectBlockchain('0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb');
console.log(chains); // ['ethereum', 'polygon']

🎨 Framework Integration

React Example

import { useState } from 'react';
import { validateAddress } from 'validator0x';

function WalletInput() {
  const [address, setAddress] = useState('');
  const [error, setError] = useState('');

  const handleValidate = (value: string) => {
    setAddress(value);
    const result = validateAddress(value, 'ethereum');

    if (!result.valid) {
      setError(result.error || 'Invalid address');
    } else {
      setError('');
    }
  };

  return (
    <div>
      <input
        type="text"
        value={address}
        onChange={(e) => handleValidate(e.target.value)}
        placeholder="Enter Ethereum address"
      />
      {error && <p style={{ color: 'red' }}>{error}</p>}
    </div>
  );
}

Next.js API Route

import { NextApiRequest, NextApiResponse } from 'next';
import { validateAddress } from 'validator0x';

export default function handler(req: NextApiRequest, res: NextApiResponse) {
  const { address, blockchain } = req.body;

  const result = validateAddress(address, blockchain);

  if (result.valid) {
    res.status(200).json({ success: true, data: result });
  } else {
    res.status(400).json({ success: false, error: result.error });
  }
}

Express.js Backend

import express from 'express';
import { validateAddress } from 'validator0x';

const app = express();
app.use(express.json());

app.post('/validate', (req, res) => {
  const { address, blockchain } = req.body;

  const result = validateAddress(address, blockchain);

  res.json(result);
});

app.listen(3000);

Vue.js Example

<template>
  <div>
    <input
      v-model="address"
      @input="validateWallet"
      placeholder="Enter wallet address"
    />
    <p v-if="error" class="error">{{ error }}</p>
    <p v-if="valid" class="success">✓ Valid address</p>
  </div>
</template>

<script setup>
import { ref } from 'vue';
import { validateAddress } from 'validator0x';

const address = ref('');
const error = ref('');
const valid = ref(false);

const validateWallet = () => {
  const result = validateAddress(address.value, 'ethereum');
  valid.value = result.valid;
  error.value = result.error || '';
};
</script>

🛠️ Supported Blockchains

Blockchain Type Formats Supported
Ethereum 'ethereum' Hex (0x...), EIP-55 checksum
Polygon 'polygon' Hex (0x...), EIP-55 checksum
Solana 'solana' Base58 (32 bytes)
Bitcoin 'bitcoin' P2PKH, P2SH, Bech32, Bech32m

⚙️ Validation Options

Strict Mode

Enable strict checksum validation for EVM chains:

const result = validateAddress(
  '0x742d35cc6634c0532925a3b844bc9e7595f0beb', // wrong checksum
  'ethereum',
  { strict: true }
);
// result.valid will be false due to incorrect checksum

Network Validation

Validate specific network addresses:

const result = validateAddress(
  'tb1qw508d6qejxtdg4y5r3zarvary0c5xw7kxpjzsx',
  'bitcoin',
  { network: 'testnet' }
);

🚨 Error Handling

import { validateAddress, ValidationError } from 'validator0x';

const result = validateAddress(address, blockchain);

if (!result.valid) {
  switch (result.details?.errorCode) {
    case ValidationError.INVALID_FORMAT:
      console.error('Address format is incorrect');
      break;
    case ValidationError.INVALID_CHECKSUM:
      console.error('Checksum validation failed');
      break;
    case ValidationError.INVALID_LENGTH:
      console.error('Address length is invalid');
      break;
    default:
      console.error(result.error);
  }
}

📚 Next Steps

  • Check out Examples for more real-world use cases
  • Read the full API Reference for detailed documentation
  • See FAQ for common questions

Need help? Open an issue on GitHub!

validator0x

npm


⚡ Quick Start

npm install validator0x

💖 Support


v0.1.1 | MIT License

Clone this wiki locally