DEV Community

Cover image for @xchainjs/xchain-util: Install, Use & Build Cross-Chain Crypto Apps (with TypeScript)
bock-studio
bock-studio

Posted on

@xchainjs/xchain-util: Install, Use & Build Cross-Chain Crypto Apps (with TypeScript)

When building blockchain applications, reusability, consistency, and reliability are critical.
That’s exactly where @xchainjs/xchain-util shines.

  • In this article, we’ll cover:
  • What @xchainjs/xchain-util is
  • How to install it
  • How to use it in real projects
  • Why it’s one of the best utility libraries for multi-chain crypto development
  • How it fits into the XChainJS ecosystem

What is @xchainjs/xchain-util?

@xchainjs/xchain-util is a utility package for XChainJS, a TypeScript-based blockchain SDK designed to work with multiple blockchains through a unified API.

This package provides shared helper functions, types, and primitives that are used across the entire XChainJS ecosystem.

  • xchainjs
  • xchainjs util
  • blockchain utility library
  • multi-chain JavaScript SDK
  • TypeScript crypto utilities
  • THORChain JavaScript tools
  • cross-chain development

Why **@xchainjs/xchain-util **Exists

When building blockchain SDKs, many operations are repeated across chains:

  • Asset formatting
  • Decimal & amount conversions
  • Chain-agnostic helpers
  • Common types and constants
  • Validation utilities

Instead of duplicating this logic in every package, XChainJS centralizes it in @xchainjs/xchain-util.

👉 This leads to:

  • Cleaner code
  • Fewer bugs
  • Consistent behavior across blockchains

Installation

Installing @xchainjs/xchain-util is straightforward using npm or yarn
Using npm

`> bash

npm install @xchainjs/xchain-util`

Using yarn

`> bash

yarn add @xchainjs/xchain-util`

This package is typically used together with other XChainJS clients, such as:

  • @xchainjs/xchain-bitcoin
  • @xchainjs/xchain-ethereum
  • @xchainjs/xchain-thorchain

How to Use @xchainjs/xchain-util
Below are some real-world usage examples showing why this library is essential for blockchain developers.

Working with Assets
XChainJS represents assets in a standardized format across chains.

`> import { Asset, assetFromString } from '@xchainjs/xchain-util'

const asset: Asset | null = assetFromString('BTC.BTC')
if (asset) {
console.log(asset.chain) // BTC
console.log(asset.symbol) // BTC
}`
✅ This ensures consistent asset handling across all supported blockchains.

Amount & Decimal Utilities
Blockchain apps often struggle with precision and decimals.
@xchainjs/xchain-util provides safe helpers for that.

`> import { assetAmount, baseAmount } from '@xchainjs/xchain-util'

const amount = assetAmount(1.5)
const base = baseAmount(150000000)
console.log(amount.amount().toString())
console.log(base.amount().toString())`

This is crucial for:

  • Wallets
  • DeFi apps
  • Cross-chain swaps
  • AMMs (like THORChain

Chain-Agnostic Design
One of the biggest advantages of XChainJS is chain abstraction.

Thanks to @xchainjs/xchain-util, developers can write logic that works the same way for:

  • Bitcoin
  • Ethereum
  • THORChain
  • Binance Chain
  • Litecoin
  • And more This makes it ideal for cross-chain wallets and DeFi platforms.

Why @xchainjs/xchain-util Is the Best Utility Library for XChainJS

Let’s be honest: utility libraries are everywhere.
So why is this one special?

  1. Built for Multi-Chain from Day One

Unlike generic crypto libraries, @xchainjs/xchain-util is designed specifically for cross-chain development.

  1. TypeScript First

Strong typing means:

  • Fewer runtime errors
  • Better IDE autocomplete
  • Safer refactoring

Perfect for professional blockchain development.

  1. Battle-Tested in Production

This package is used internally by:

  • THORChain tools
  • XChainJS clients
  • Real DeFi applications

That means it’s production-ready, not experimental.

  1. Clean, Focused Scope

It does one thing well:

Provide shared utilities for blockchain SDKs

No bloat. No unnecessary abstractions.

When Should You Use @xchainjs/xchain-util*?*

You should use it if you are:

  • Building a crypto wallet
  • Developing a cross-chain DeFi app
  • Working with THORChain
  • Using XChainJS clients
  • Writing blockchain code in TypeScript / JavaScript

If any of those apply — this package is a no-brainer.

Final Thoughts
@xchainjs/xchain-util may look like a small helper package, but it plays a critical role in the XChainJS ecosystem.

It improves:

  • Code quality
  • Consistency
  • Developer experience
  • Cross-chain reliability

If you’re serious about blockchain development with JavaScript or TypeScript, this utility library is something you definitely want in your stack.

🔑 SEO Summary (for dev.to)

Primary keywords:

  • xchainjs
  • xchainjs util
  • blockchain utility library
  • TypeScript blockchain SDK
  • cross-chain JavaScript
    Secondary keywords:

  • THORChain development

  • crypto utilities

  • DeFi JavaScript tools

  • multi-chain wallet development

Top comments (0)