xchainjs: TypeScript Web3 Transaction Example & Monitoring
Quick summary: Need to check a transaction hash, verify confirmations, and wire monitoring into a TypeScript backend? This guide shows pragmatic xchainjs + web3 patterns, sample code, monitoring strategies and SEO-friendly FAQ for implementers.
1. SERP analysis & user intent (top-level summary)
I analyzed typical English-language top-10 search results for your keywords (xchainjs, web3 transaction tracking, transaction hash lookup, blockchain explorer queries). The SERP profile usually contains: official docs and GitHub repos, short tutorial posts (Dev.to / Medium), transaction explorers (Etherscan, BscScan, Blockchair), and SaaS monitoring vendors (Alchemy, Tenderly, Blocknative, QuickNode).
Detected user intents by keyword cluster:
- Informational: “web3 transaction example”, “transaction confirmation check”, “blockchain transaction history” — users want how-to and explanations.
- Transactional / Commercial: “blockchain tx monitoring”, “web3 transaction monitoring”, “blockchain transaction api” — users compare tools or look for APIs/services.
- Navigation / Resource: “xchainjs”, “xchainjs transaction api”, “typescript blockchain sdk” — users seek docs or SDK repos.
- Mixed: “check transaction hash”, “crypto transaction status” — could be direct lookup or learning how to do it programmatically.
Competitors’ content depth typically covers: quick commands for explorers, minimal code snippets, SaaS landing pages highlighting real-time webhooks/SDKs, and a few in-depth blog posts showing end-to-end patterns. To outrank them you need precise code examples in TypeScript, monitoring architecture, and quick, copy-pastable snippets that answer voice/featured-snippet queries.
2. Semantic core (expanded & clustered)
Base keywords you gave were used to build the clusters below. Use these organically in titles, H2/H3 and first 150 words for stronger signals.
Primary (main target) - xchainjs - xchainjs transaction example - xchainjs transaction api - web3 transaction example - typescript blockchain sdk Supporting (monitoring / lookup) - check transaction hash - transaction hash lookup - blockchain transaction lookup - blockchain transaction explorer - block explorer - web3 transaction checker - crypto transaction status - transaction confirmation check Tools / development - web3 development - web3 transaction tracking - web3 transaction monitoring - blockchain transaction api - blockchain backend development - blockchain developer tools - web3 wallet development - crypto wallet transaction check Advanced / cross-chain - cross chain transaction monitoring - defi transaction tracking - blockchain tx monitoring - crypto transaction confirmation - blockchain transaction history
LSI / synonyms to sprinkle:
- tx hash / txid / transaction receipt
- confirmations / block confirmations / finality
- node RPC / JSON-RPC / provider
- explorer API / indexer / transaction index
3. Popular user questions (PAA & forum‑inspired)
Collected likely People Also Ask / forum questions for this topic (5–10):
- How do I check a transaction by hash programmatically?
- What does transaction confirmation mean and how many confirmations do I need?
- How to get transaction receipt in TypeScript using xchainjs / web3?
- How to monitor pending transactions in real time?
- How to correlate cross-chain transactions and track status?
- What tools provide webhook alerts for tx confirmations?
- Why is my transaction pending for a long time?
- How to fetch transaction history for a wallet in TypeScript?
Final FAQ (3 most relevant) chosen below:
- How do I check an xchainjs transaction by hash?
- How many confirmations are needed to consider a crypto transaction final?
- Can I monitor cross-chain transactions with xchainjs?
4. Article — Practical xchainjs & TypeScript transaction check (deep, actionable)
Why a reliable transaction check matters
Every web3 flow that moves funds or changes state must verify the transaction outcome before proceeding. Blindly assuming success is the fastest route to angry users and bug reports. On top of that, different chains expose different finality guarantees: a “confirmed” tx on one chain can be effectively reversible on another.
From a backend perspective, you want idempotence, clear retry semantics, and a way to surface stale or re-orged transactions. That requires three primitives: access to an RPC or explorer API, a receipt-query function, and a confirmation counting strategy that fits your risk profile.
This article focuses on xchainjs patterns plus generic web3/TypeScript snippets so you can plug them into a blockchain backend or wallet service and start answering “is my tx done?” reliably.
xchainjs transaction example (TypeScript)
Quick answer first: the core flow is—submit tx → get tx hash → poll for receipt → count confirmations → react. Here’s a concise TypeScript example using a generic web3 provider pattern but labeled for xchainjs-style integration.
// PSEUDO/ADAPTABLE TypeScript example
import { providers } from 'ethers'; // or xchainjs provider wrapper
const provider = new providers.JsonRpcProvider(process.env.RPC_URL);
async function checkTx(txHash: string, requiredConfirmations = 6) {
// getTransactionReceipt returns null while pending
let receipt = await provider.getTransactionReceipt(txHash);
if (!receipt) return { status: 'pending' };
const currentBlock = await provider.getBlockNumber();
const confirmations = receipt.blockNumber ? currentBlock - receipt.blockNumber + 1 : 0;
const success = receipt.status === 1;
return { status: success ? 'success' : 'failed', confirmations, receipt };
}
Notes: xchainjs is a multi-chain TypeScript SDK ecosystem—where available, use its network-specific provider helpers. If your SDK returns receipts differently, normalize the structure so status, blockNumber and logs are predictable. Also, always handle the null-receipt case (transaction still in mempool).
For a concrete tutorial-style example see the community writeup: xchainjs check transaction example. I link it because it demonstrates practical SDK usage and maps well to the snippet above.
Polling, webhooks and event-driven monitoring
Polling is simple and reliable but can be wasteful. For production scale you should combine short-term polling (until included in a block) with webhook or event-driven alerts for confirmations. Many provider platforms (Alchemy, QuickNode, Blocknative) expose webhooks and websockets that emit txn-included and confirmation events.
Design considerations: set a backoff policy for polling (e.g., 1s → 2s → 5s → 15s), cap total polling time, and move orphaned txs to manual review. Use idempotent handlers: your confirmation webhook might be delivered multiple times; always check receipt status and confirmations before marking final.
If you insist on a pure indexer approach, maintain a database of tx hashes and index receipts once a new block arrives. This gives you fast queryable history for wallet UIs and audits.
Confirmations, finality and risk tolerance
There is no universal number of confirmations. Common heuristics: 1–2 for low-risk, fast chains (e.g., some layer-2s), 6–12 for Ethereum-class chains, and more for high-value financial flows. Consider the cost of a reorg versus the cost of delayed UX.
Implement a confirmation policy in business logic: immediate optimistic flows (show “pending”) vs final settlement actions (only run after N confirmations). Keep logs of blockNumber used for finalization so you can audit decisions if a chain reorg happens.
Pro tip: present both UX states to the user—“On-chain (1/12 confirmations)” and “Settled” — users like transparency and it reduces support tickets.
Monitoring architecture & tooling (what to use)
For real-time transaction monitoring combine:
- RPC provider / indexer for receipt data (Alchemy, QuickNode, Infura or self-hosted node)
- Explorer APIs for cross-verification (Etherscan / chain-specific explorers)
- A monitoring/broker that supports webhooks and retry semantics (Blocknative, Tenderly, Alchemy Notify)
Example flow: submit tx via xchainjs → push tx hash to your monitoring queue → short-term websocket subscription for inclusion → on inclusion, start confirmation counter → on N confirmations, emit finalization webhook to downstream services.
If you need to track cross-chain flows (bridges), correlate tx hashes from both sides via the bridge’s relayer logs or index-scraped events; there is no single canonical txid for a multi-step cross-chain transfer, so you must build correlation keys (sender, nonce, bridge tx id).
Production tips and common pitfalls
Always handle these edge cases: timeouts (tx not mined), low gas causing long pending, replaced transactions (EIP-1559/replacement), and chain reorgs. Use provider.getTransactionReplacement or check for same-from/same-nonce replacements.
Persist receipts and blockNumbers in your DB for auditing. Do not trust single-provider status: cross-check with an explorer API if consistency matters (e.g., when reconciling balances).
Finally, batch requests where possible and use multicall/indexer queries for historical wallet transaction history to avoid rate-limited RPC calls.
5. SEO & snippet optimization guidance
To target featured snippets and voice queries, ensure you include short direct answers (1–2 sentences) right after headings that reflect the search query. Example: For “check transaction hash” include a short block that says: “Use provider.getTransactionReceipt(txHash) — if it returns null the tx is pending; if receipt.status===1 it’s successful.”
Use structured data (FAQ) — provided above — to improve SERP real estate. Put the main keyword in the page title, H1, and first 100 words. Use variations and LSI terms across H2s and the semantic core list (shown earlier) as anchor text where appropriate.
Voice optimization: craft a 30–40 word summary that directly answers the question. Use conversational phrases like “To check a tx hash, call…” because voice assistants prefer natural phrasing.
6. FAQ (final three questions)
How do I check an xchainjs transaction by hash?
Call your provider or explorer API to fetch the transaction receipt (getTransactionReceipt). If receipt is null the tx is pending; if receipt.status === 1 it’s successful. Use xchainjs’s provider helpers where available to normalize network specifics.
How many confirmations are needed to consider a crypto transaction final?
There is no single number. For safety: 1–2 on fast L2s, 6–12 on Ethereum-class chains, more for very high-value operations. Choose N based on the chain’s reorg profile and your business risk tolerance.
Can I monitor cross-chain transactions with xchainjs?
xchainjs helps with per-chain interaction. Cross-chain monitoring requires aggregating per-chain receipts, bridge relayer events, or third-party indexers and correlating transactions. There is no universal txid across chains—use composite keys and relayer logs.
7. Backlinks (anchor links from keywords)
Useful references (linked from keyword anchors):
- xchainjs check transaction example
- blockchain transaction explorer (Etherscan)
- web3 transaction tracking (Alchemy Notify)
Embed these backlinks where relevant in product pages or technical docs using exact-match or partial-match anchor text from the semantic core above.
8. Deliverables & publication checklist
This HTML includes: SEO Title, meta Description, H1, semantic core block, in-depth TypeScript examples, monitoring architecture, and FAQ + JSON-LD for FAQ. Before publishing:
- Replace placeholder RPC_URL and SDK imports with your production values.
- Confirm license/attribution for any copied snippets (this content is original).
- Ensure external links open in new tabs and track click-throughs in analytics.