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 🙏

© 2026 – Pkg Stats / Ryan Hefner

stx-utils

v1.0.0

Published

Lightweight utilities for Stacks (STX) dApp development — formatting, validation, address helpers, block-time estimation, and more.

Readme

stx-utils

Lightweight, zero-dependency utilities for Stacks (STX) dApp development.

Install

npm install stx-utils

Features

| Module | Description | |---|---| | Formatting | Convert between STX and microSTX, display with units | | Address | Validate, shorten, and parse Stacks principals | | Blocks | Estimate durations from block counts, "time ago" helpers | | Validation | Validate names, stake amounts, and principals | | Errors | Decode Clarity error codes into human-readable messages | | Time | Format dates and relative timestamps | | Explorer | Build Hiro explorer URLs for txs, addresses, contracts |

Usage

import {
  formatSTX,
  toMicroSTX,
  shortenAddress,
  isValidAddress,
  blocksToTime,
  blocksAgo,
  validateStake,
  decodeError,
  txUrl,
} from 'stx-utils';

// STX formatting
formatSTX(1_500_000);        // "1.50"
formatSTX(1_500_000, 4);     // "1.5000"
toMicroSTX(2.5);             // 2_500_000

// Address utilities
shortenAddress('SP1M46W6CVGAMH3ZJD3TKMY5KCY48HWAZK0DYG193');
// "SP1M46...G193"

isValidAddress('SP1M46W6CVGAMH3ZJD3TKMY5KCY48HWAZK0DYG193'); // true
isValidAddress('not-valid');  // false

// Block time
blocksToTime(144);           // "1 day"
blocksAgo(1000, 994);        // "~1h ago"

// Validation
validateStake(0.5);          // null (valid)
validateStake(0.01);         // "Minimum stake is 0.1 STX"

// Error decoding
decodeError(105);            // "Already checked in today"
decodeError(999);            // "Unknown error (u999)"

// Explorer URLs
txUrl('0xabc123');
// "https://explorer.hiro.so/txid/0xabc123?chain=mainnet"

API Reference

Formatting

  • formatSTX(microSTX, decimals?) — Convert microSTX to display string
  • toMicroSTX(stx) — Convert STX to microSTX (floored)
  • toSTX(microSTX) — Convert microSTX to numeric STX
  • formatSTXWithUnit(microSTX) — Format with automatic unit suffix

Address

  • isValidAddress(address) — Check standard principal validity
  • isContractPrincipal(address) — Check contract principal validity
  • getAddressNetwork(address) — Returns "mainnet", "testnet", or null
  • shortenAddress(address, startChars?, endChars?) — Truncate for display
  • parseContractPrincipal(principal) — Extract [address, name] tuple

Blocks

  • blocksToTime(blocks) — Human-readable duration from block count
  • blocksToSeconds(blocks) — Convert blocks to seconds
  • secondsToBlocks(seconds) — Convert seconds to blocks
  • blocksAgo(currentBlock, targetBlock) — Relative block time
  • estimateBlockDate(targetBlock, currentBlock, now?) — Estimated Date

Validation

  • validateName(name, maxLength?) — Validate a Clarity string input
  • validateStake(stx, minMicroSTX?) — Validate stake amount
  • validatePrincipal(principal) — Validate standard or contract principal

Errors

  • decodeError(code) — Look up a Clarity error code
  • registerErrors(errors) — Add or override error codes
  • getErrorRegistry() — Get all registered codes

Time

  • formatDate(timestamp, locale?) — Format a UNIX timestamp
  • timeAgo(timestamp) — Relative time string

Explorer

  • txUrl(txId, network?) — Transaction explorer link
  • addressUrl(address, network?) — Address explorer link
  • contractUrl(principal, network?) — Contract explorer link

Constants

| Name | Value | Description | |---|---|---| | MICRO_PER_STX | 1_000_000 | microSTX per STX | | SECONDS_PER_BLOCK | 600 | Estimated seconds per block | | BLOCKS_PER_DAY | 144 | Estimated blocks per day | | DEFAULT_MIN_STAKE | 100_000 | Default minimum stake (microSTX) | | DEFAULT_MAX_NAME_LENGTH | 50 | Default max name length |

License

MIT