DEV Community

Fabricio Viskor
Fabricio Viskor

Posted on

# XChainJS Check Transaction Example

This example demonstrates how to check and track a blockchain transaction using XChainJS.

It shows how to:

  • query transaction data by hash
  • check transaction status and confirmations
  • work with chain clients in a unified way
  • build transaction monitoring logic for wallets and backends

The example is fully runnable and available on GitHub and CodeSandbox.


๐Ÿ”— Live Demo & Source Code


๐Ÿ“Œ What This Example Does

This project demonstrates how to check the status of a transaction using XChainJS.

It covers:

  • fetching transaction information by hash
  • checking confirmations and finality
  • handling pending vs confirmed transactions
  • using a chain-agnostic API for transaction lookup

This example is useful for developers building:

  • crypto wallets
  • transaction history pages
  • blockchain explorers
  • monitoring and alerting services
  • cross-chain backends

๐Ÿงฐ Tech Stack

  • TypeScript
  • Node.js
  • XChainJS
  • @xchainjs/xchain-util
  • Chain clients from XChainJS ecosystem

๐Ÿ“‚ Project Location

Inside the XChainJS monorepo:

examples/
 โ””โ”€ check-tx/
Enter fullscreen mode Exit fullscreen mode

The example focuses on transaction status logic, without UI code.


๐Ÿ”„ How Transaction Checking Works

Transaction Hash
      โ†“
XChainJS Chain Client
      โ†“
Fetch Transaction Data
      โ†“
Check Confirmations & Status
      โ†“
Return Result
Enter fullscreen mode Exit fullscreen mode

๐Ÿงฉ Core Concepts

Transaction Hash

A transaction hash uniquely identifies an on-chain transaction.
This example shows how to use a transaction hash to query the blockchain
and retrieve transaction details.


Transaction Status

Depending on the chain, a transaction can be:

  • pending
  • confirmed
  • failed

XChainJS abstracts these differences and provides a consistent interface
for checking transaction status across chains.


โš™๏ธ Installation

Clone the repository

git clone https://github.com/xchainjs/xchainjs-lib.git
cd xchainjs-lib/examples/check-tx
Enter fullscreen mode Exit fullscreen mode

Install dependencies

npm install
Enter fullscreen mode Exit fullscreen mode

Run the example

npm start
Enter fullscreen mode Exit fullscreen mode

๐Ÿš€ Running in the Browser

You can also run this example instantly using CodeSandbox:

https://codesandbox.io/p/devbox/github/xchainjs/xchainjs-lib/tree/master/examples/check-tx


๐Ÿงช Code Example (Simplified)

import { getClient } from '@xchainjs/xchain-thorchain'

const txHash = 'YOUR_TRANSACTION_HASH'

async function checkTx() {
  const client = getClient()
  const tx = await client.getTransactionData(txHash)

  if (!tx) {
    throw new Error('Transaction not found')
  }

  console.log(tx)
}

checkTx()
Enter fullscreen mode Exit fullscreen mode

This pattern can be reused for different chains by switching clients.


โœ… Why Use XChainJS for Transaction Monitoring

  • Unified API for multiple blockchains
  • TypeScript-first for safer code
  • Reusable client abstractions
  • Suitable for wallets and production backends

๐Ÿง  When This Example Is Useful

Use this example if you are:

  • learning how transaction tracking works
  • building a wallet transaction history
  • implementing confirmations logic
  • monitoring cross-chain transactions
  • working with XChainJS clients

๐Ÿ”— Related Resources


๐Ÿ“ Summary

This example provides a simple, runnable reference for checking
blockchain transactions using XChainJS.

It is a solid foundation for building transaction-aware applications
such as wallets, explorers, and monitoring services.

Top comments (0)