# XChainJS Check Transaction Example
Source: Dev.to
Live Demo & Source Code
- Live demo (CodeSandbox):
- Source code (GitHub):
What This Example Does
The project shows how to check the status of a transaction with 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
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 the XChainJS ecosystem
Project Location
Inside the XChainJS monorepo:
examples/
└─ check-tx/
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
Core Concepts
Transaction Hash
A transaction hash uniquely identifies an on‑chain transaction. This example shows how to use a 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
Install dependencies
npm install
Run the example
npm start
Running in the Browser
You can also run this example instantly using CodeSandbox.
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()
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
- XChainJS GitHub:
- XChainJS utilities:
- Live check transaction example:
Summary
This example provides a simple, runnable reference for checking blockchain transactions using XChainJS. It serves as a solid foundation for building transaction‑aware applications such as wallets, explorers, and monitoring services.