xchainjs Transaction Example & Web3 Transaction Tracking Guide

React Tooltip: Install, Customize & Position Tooltips
15 stycznia 2026
Jak ocenić stan używanych opon?
19 stycznia 2026
Pokaż wszystkie





xchainjs Transaction Example & Web3 Transaction Tracking Guide




xchainjs Transaction Example & Web3 Transaction Tracking Guide

Quick answer: Use xchainjs to sign/send the transaction, capture the returned transaction hash, and then use a provider (web3/ethers) or explorer API to lookup the transaction hash and poll for confirmations. This guide shows a TypeScript example, monitoring patterns, common pitfalls, and production-ready best practices for blockchain transaction tracking.

How to send a transaction with xchainjs and check the transaction hash

xchainjs libraries are typically used to build cross-chain wallets and clients in TypeScript and JavaScript. When you call the client to send or broadcast a transaction, most xchain clients return a transaction ID (transaction hash) or a broadcast response containing that hash. That hash is the single canonical identifier you use to check the transaction status using a node RPC, Web3 provider, or a block explorer API.

Below is a concise TypeScript example that demonstrates the end-to-end flow: sign/send with a client, capture the tx hash, then check its status using an RPC provider (ethers.js used for clarity). Replace the client call with your specific xchainjs client call if it returns a different shape.

// TypeScript example: send with xchain client, then check via ethers provider
import { ethers } from "ethers";
// Replace this with the actual xchainjs client you use
// import { XChainClient } from "@xchainjs/xchain-client";

async function sendAndTrackTx() {
  // 1) Build and sign/send the tx with your xchainjs client (pseudo call)
  // const xclient = new XChainClient({ network: "mainnet", wallet: myWallet });
  // const result = await xclient.sendTransaction({ to, amount, memo });
  // const txHash = result.txID || result.txHash;

  // Example: pseudo txHash returned by xchain client
  const txHash = "0x1234...abcd"; // <-- replace with actual tx hash

  // 2) Use an ethers provider (or web3) to poll the transaction receipt
  const provider = new ethers.providers.JsonRpcProvider(process.env.RPC_URL);
  const receipt = await provider.getTransactionReceipt(txHash);

  // If receipt is null, transaction is not yet mined; poll until mined
  if (!receipt) {
    // simple polling loop (production: use exponential backoff / webhook)
    let attempts = 0;
    while (!receipt && attempts < 60) {
      await new Promise(res => setTimeout(res, 5000)); // 5s
      const r = await provider.getTransactionReceipt(txHash);
      if (r) return r; // mined
      attempts++;
    }
    throw new Error("Transaction not mined within timeout");
  }

  return receipt;
}
  

Key takeaways from the example: you must capture and persist the transaction hash immediately after broadcast, and you should query a reliable RPC or explorer API to track the confirmation lifecycle. Storing the hash lets you perform offline diagnostics and provide the user with a permanent link to a transaction explorer.

For a practical xchainjs-focused reference, you can consult a community example here: xchainjs check transaction example.

Polling, confirmations, and handling re-orgs: practical web3 transaction tracking

On most chains a transaction is considered „mined” when included in a block, but „final” status depends on the number of confirmations you require. For Ethereum-like chains, 12 confirmations is often considered safe for high-value transfers, but the required count changes by chain and risk profile. The monitoring code should track both the blockNumber and confirmations reported in the receipt.

A robust monitor accounts for chain reorganizations (re-orgs). A simple pattern: treat a transaction as „tentatively confirmed” once mined, mark it „finalized” only after N confirmations, and keep the receipt on disk for N blocks (or until confidently finalized). If a re-org drops the tx out of the canonical chain, your system should detect the missing receipt and trigger a reconcile workflow—either re-broadcast or alert an operator.

Polling strategies range from short-interval polling (every 3–10s) for UX responsiveness, to webhook/RPC push via third-party services for scalable backends. Use exponential backoff for polling after repeated null receipts, and consider fallbacks: switch to a different RPC endpoint or a reliable explorer API if the primary provider is slow.

APIs, explorers and tools for transaction lookup and monitoring

There are three common ways to lookup a transaction hash: directly query a node RPC (provider.getTransactionReceipt), use an explorer API (Etherscan, BscScan, etc.), or use a third-party monitoring service that provides webhooks and analytics. Each has trade-offs: RPC gives the freshest on-chain state; explorers often provide enriched metadata and easier rate-limits; third-party monitors provide webhooks, retry logic, and easier scaling.

Useful links and APIs:

For production monitoring at scale, implement a background worker (watcher) that:
– persists tx hashes to durable storage,
– polls receipts and confirmation counts,
– emits events (webhooks, message queue) when status changes,
– and reconciles missing or failed transactions with operator alerts.

TypeScript SDK & backend patterns for blockchain transaction monitoring

When building a TypeScript backend around xchainjs or any Web3 client, architect for resiliency. Keep a small, focused SDK layer that abstracts signer details (wallets, private keys, hardware modules) and provides clear return shapes (txHash, broadcastStatus). That makes the monitoring layer independent from wallet variations and easier to test.

Event-driven architectures scale well: once a txHash is persisted, push a „tx.pending” event into a queue. Workers consume events, check provider.getTransactionReceipt(txHash), update DB records, and push „tx.mined” or „tx.confirmed” events only once confirmations pass your threshold. This separation keeps web requests fast and prevents blocking user flows on long chain finality times.

Error handling is essential. Common problems include nonce errors, insufficient gas, network timeouts, and replaced transactions. Implement explicit states in your DB: pending, broadcast-failed, mined, confirmed, replaced, and failed. Persist raw RPC responses for debugging and include links to transaction explorers for easy manual inspection.

Implementation checklist and troubleshooting tips

Before shipping a tx-monitoring system, verify these items: correct capture of transaction hash in all code paths, robust persistence with retries, at least two independent RPC endpoints for fallback, a confirmation threshold configured per-chain, and alerting on abnormal latencies or replace-by-fee events.

When a user reports a missing transaction, the immediate diagnostic steps are:
– verify the txHash string and check for typos,
– query provider.getTransactionReceipt(txHash),
– if null, query an explorer API (some explorers may show pending mempool txs),
– check mempool and nonce gaps for stuck transactions, and
– if replaced, find the replacement tx hash and follow that instead.

For cross-chain or DeFi transaction monitoring, ensure you correlate internal business IDs (order IDs, swap IDs) with on-chain tx hashes and external explorer links. Cross-chain transactions often require an additional reconciliation step across multiple chains and bridge logs.

Semantic core (keyword clusters)

Primary (high intent, production):

  • xchainjs
  • xchainjs transaction example
  • transaction hash lookup
  • blockchain transaction explorer
  • web3 transaction tracking
  • crypto transaction status
  • typescript blockchain sdk

Secondary (supporting intent, development):

  • check transaction hash
  • web3 transaction checker
  • blockchain tx monitoring
  • transaction confirmation check
  • web3 wallet development
  • blockchain backend development

Clarifying / LSI phrases (queries & voice search optimized):

  • how to check a transaction by hash
  • how many confirmations for ethereum
  • monitoring pending transactions
  • crypto wallet transaction check
  • cross chain transaction monitoring
  • defi transaction tracking
  • blockchain transaction history

Suggested micro-markup

To improve discoverability and enable rich results, add:
– FAQ schema (JSON-LD) for the FAQ below.
– Article schema (headline, description, author, publish date).
The FAQ JSON-LD block is included immediately after the article content.

Top user questions (selected)

We found common user questions that guide the FAQ. The three most common selected for the FAQ below:

  • How do I check a transaction hash using xchainjs or web3?
  • What does pending vs confirmed mean and how many confirmations are safe?
  • How can I monitor transactions reliably in production?

FAQ

How do I check a transaction hash using xchainjs or web3?

Capture the transaction hash at broadcast, then query an RPC provider or explorer using provider.getTransactionReceipt(txHash) (ethers/web3). If receipt is null, poll until the tx is mined or use an explorer API for mempool visibility. Persist the hash and show an explorer link for manual inspection.

What does pending vs confirmed mean and how many confirmations are safe?

„Pending” means the tx is in the mempool or not yet included in a block. „Mined” means included in a block (receipt exists). „Confirmed” means N additional blocks have been appended after the block that included the tx. The safe confirmation count varies: 12 is common for Ethereum-like chains; some L2s and fast chains use fewer confirmations. Choose based on your risk tolerance and chain characteristics.

How can I monitor transactions reliably in production?

Use durable persistence for tx hashes, background workers with exponential backoff polling, multiple RPC endpoints, and alerting. Prefer event-driven queues and webhooks for user notification. Handle re-orgs by waiting for N confirmations, and store raw responses for troubleshooting.

Helpful direct links:
xchainjs transaction example |
transaction hash lookup (Etherscan) |
web3 development docs



Call Now Button