npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@chain1/crypto-utils

v1.0.1

Published

Cryptocurrency utility functions for formatting and conversion

Downloads

9

Readme

@chain1/crypto-utils

Essential cryptocurrency utility functions for Ethereum-compatible blockchains.

Installation

npm install @chain1/crypto-utils

Features

  • Wei/Ether/Gwei conversion utilities
  • Gas fee calculations
  • Address validation
  • BigNumber operations
  • Zero-dependency ethers.js wrapper

Usage

Wei/Ether Conversion

import { formatEther, parseEther, formatGwei, parseGwei } from '@chain1/crypto-utils';

// Convert Wei to Ether
const ether = formatEther('1000000000000000000'); // "1.0"

// Convert Ether to Wei
const wei = parseEther('1.5'); // BigNumber

// Gwei conversions
const gwei = formatGwei('1000000000'); // "1.0"
const weiFromGwei = parseGwei('50'); // BigNumber

Gas Fee Calculations

import { calculateGasFee, calculateGasFeeInEther } from '@chain1/crypto-utils';
import { ethers } from 'ethers';

const gasPrice = ethers.BigNumber.from('50000000000'); // 50 Gwei
const gasLimit = ethers.BigNumber.from('21000');

// Calculate gas fee in Wei
const feeWei = calculateGasFee(gasPrice, gasLimit);

// Calculate gas fee in Ether
const feeEther = calculateGasFeeInEther(gasPrice, gasLimit); // "0.00105"

Address Validation

import { isValidAddress } from '@chain1/crypto-utils';

const valid = isValidAddress('0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb'); // true
const invalid = isValidAddress('invalid-address'); // false

Format Units

import { formatUnits, parseUnits } from '@chain1/crypto-utils';

// Format custom decimal tokens
const usdt = formatUnits('1000000', 6); // "1.0" (USDT has 6 decimals)

// Parse custom decimal tokens
const amount = parseUnits('100', 6); // BigNumber for 100 USDT

API Reference

Conversion Functions

  • formatEther(value: BigNumberish): string - Wei to Ether
  • parseEther(value: string): BigNumber - Ether to Wei
  • formatGwei(value: BigNumberish): string - Wei to Gwei
  • parseGwei(value: string): BigNumber - Gwei to Wei
  • formatUnits(value: BigNumberish, decimals: number): string - Wei to custom decimals
  • parseUnits(value: string, decimals: number): BigNumber - Custom decimals to Wei

Gas Functions

  • calculateGasFee(gasPrice: BigNumber, gasLimit: BigNumber): BigNumber - Calculate fee in Wei
  • calculateGasFeeInEther(gasPrice: BigNumber, gasLimit: BigNumber): string - Calculate fee in Ether

Validation Functions

  • isValidAddress(address: string): boolean - Validate Ethereum address

TypeScript Support

Full TypeScript support with type definitions included.

import type { BigNumber, BigNumberish } from 'ethers';

License

MIT

Repository

https://github.com/stochain/packages