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)