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
βΆ Live demo (CodeSandbox):
https://codesandbox.io/p/devbox/github/xchainjs/xchainjs-lib/tree/master/examples/check-txπ¦ Source code (GitHub):
https://github.com/xchainjs/xchainjs-lib/tree/master/examples/check-tx
π 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/
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 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
Install dependencies
npm install
Run the example
npm start
π 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()
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
https://github.com/xchainjs/xchainjs-libXChainJS utilities
https://www.npmjs.com/package/@xchainjs/xchain-utilLive check transaction example
https://codesandbox.io/p/devbox/github/xchainjs/xchainjs-lib/tree/master/examples/check-tx
π 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)