Socket
Book a DemoInstallSign in
Socket

@yaring/coinscheck

Package Overview
Dependencies
Maintainers
0
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@yaring/coinscheck

Blockchain balance checker

1.0.0
latest
npmnpm
Version published
Weekly downloads
1
Maintainers
0
Weekly downloads
 
Created
Source

Here’s a technical English translation of your provided README:

CoinsCheck

A multi-network library for checking cryptocurrency wallet balances with support for a wide range of blockchains.

Supported Networks

  • EVM (Ethereum, BSC, Polygon, etc.)
  • Bitcoin
  • Litecoin
  • Dogecoin
  • Cardano
  • Cosmos
  • Monero
  • Polkadot
  • Solana
  • TON
  • TRON

Installation

npm install @yaring/coinscheck

Key Features

  • Balance checks across various blockchain networks
  • Provider caching for performance optimization
  • Address validation for all supported networks
  • Informative error handling
  • TypeScript support

Usage Examples

Basic Usage

const { BalanceChecker } = require('@yaring/coinscheck');
const checker = new BalanceChecker({
  timeout: 30000 // optional, timeout in ms
});

// Single network balance check
const chain = {
  chainId: '1',
  rpc: 'https://eth-mainnet.public.blastapi.io',
  chainType: 'EVM',
};

const balance = await checker.checkSingleChainBalance(
  '0x742d35Cc6634C0532925a3b844Bc454e4438f44e',
  chain
);
console.log(balance);
// {
//   chainId: '1',
//   balance: '1000000000000000000',
//   chainType: 'EVM'
// }

Multi-network Balance Check

const balances = await checker.checkBalances([
  {
    address: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e',
    chain: {
      chainId: '1',
      rpc: 'https://eth-mainnet.public.blastapi.io',
      chainType: 'EVM',
    },
  },
  {
    address: 'DRpbCBMxVnDK7maPM5tGv6MvB3v1sRMC86PZ8okm21hy',
    chain: {
      chainId: 'solana-mainnet',
      rpc: 'https://api.mainnet-beta.solana.com',
      chainType: 'SOLANA',
    },
  },
]);

Address Validation

const { AddressValidator } = require('@yaring/coinscheck');

// EVM address validation
const isValidEvm = AddressValidator.validateAddress(
  '0x742d35Cc6634C0532925a3b844Bc454e4438f44e',
  'EVM'
);

// Solana address validation
const isValidSolana = AddressValidator.validateAddress(
  'DRpbCBMxVnDK7maPM5tGv6MvB3v1sRMC86PZ8okm21hy',
  'SOLANA'
);

API Reference

Class BalanceChecker

Constructor

new BalanceChecker(options?: {
  timeout?: number; // timeout in milliseconds, default is 30000
});

Methods

checkSingleChainBalance(address: string, chain: Chain): Promise<Balance>

Checks the balance for a single address in a specified network.

interface Chain {
  chainId: string;
  rpc: string;
  chainType: string;
  name?: string;
  nativeDenom?: string; // for Cosmos-based networks
}
interface Balance {
  chainId: string;
  balance: string;
  chainType: string;
  error?: string;
}
checkBalances(items: CheckItem[]): Promise<Balance[]>

Checks balances for an array of addresses across different networks.

interface CheckItem {
  address: string;
  chain: Chain;
}
dispose(): void

Releases resources and closes connections to providers.

Class AddressValidator

Static Methods

validateAddress(address: string, chainType: string): boolean

Validates the address format for a given network type.

validateAddressFormat(address: string, chainType: string): boolean

Checks if the address matches the regular expression for the specified network type.

getAddressExamples(): Record<string, string>

Returns examples of valid addresses for each network type.

getTestAddresses(): Record<string, { valid: string[], invalid: string[] }>

Provides sets of valid and invalid addresses for testing.

Supported Address Formats

  • EVM: 0x[0-9a-fA-F]{40}
  • Solana: [1-9A-HJ-NP-Za-km-z]{32,44}
  • Cosmos: [chain-prefix]1[a-zA-Z0-9]{38}
  • Bitcoin: (1|3|bc1)[a-zA-HJ-NP-Z0-9]{25,62}
  • Polkadot: [1-9A-HJ-NP-Za-km-z]{47,48}
  • TRON: T[A-Za-z1-9]{33}
  • TON: (?:EQ|UQ)[a-zA-Z0-9_-]{48}

Error Handling

The library provides informative error messages for each network:

try {
  const balance = await checker.checkSingleChainBalance(address, chain);
} catch (error) {
  console.error(error.message);
  // Example messages:
  // "EVM balance check failed: invalid response from RPC"
  // "Solana balance check failed: invalid address"
  // "TRON balance check failed: network error"
}

License

MIT

Let me know if you need further adjustments!

Keywords

blockchain

FAQs

Package last updated on 02 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.