DEV Community

Lavrent Sar
Lavrent Sar

Posted on

Watch-Only Wallets for Engineers: Address Monitoring, RPC Polling, and Payment UX

Watch-Only Wallets for Engineers: Address Monitoring, RPC Polling, and Payment UX

You built a checkout flow. The user sees a QR code, scans it, and sends tokens. Then you wait. How do you know the money actually arrived without holding the private keys on your production servers? This is where watch-only wallets come in. They let software monitor blockchain state changes—deposits, confirmations, balance shifts—without ever touching signing material. For engineers building payment systems, separating observation from execution isn’t just a security preference. It’s usually an architectural requirement.

Holding private keys on a web-facing backend invites disaster. If that server is compromised, funds are gone. A watch-only setup restricts the backend to read operations. You import a public address or an extended public key (xpub/zpub) into your database or wallet node, and your application simply watches the ledger.

What Exactly Is a Watch-Only Wallet?

A watch-only wallet tracks addresses and transactions but cannot initiate them. It lacks the cryptographic secrets required to sign data. Think of it as a read-only view of a bank account statement. You can see every deposit and withdrawal, but you can’t write checks.

In practice, this usually means importing an address string or a descriptor into a node or a lightweight library. For UTXO-based chains like Bitcoin, developers often use extended public keys to derive an entire tree of receiving addresses deterministically. For account-based networks like TRON or Ethereum, you typically just monitor a specific base58 or hex address.

The core principle remains the same across networks: decouple the system that detects payments from the system that moves funds. Your API server handles the former. An air-gapped machine or a hardware security module handles the latter.

Monitoring Addresses via RPC

To detect incoming payments, your application needs to query the network. Developers generally choose between running a local full node or calling a remote procedure call (RPC) endpoint.

On TRON, which processes a significant volume of stablecoin payments, you interact with the network using HTTP APIs provided by full nodes (often referred to as TronGrid or similar infrastructure, though policies change). To check if a user paid an invoice, you poll the node for transactions involving your watch-only address.

Here is a simplified pattern for checking TRC20 token transfers using a standard JSON-RPC or REST approach. You query the contract's Transfer event logs filtered by your topic (the padded address):

// Conceptual example: polling for TRC20 deposits
const endpoint = "https://api.trongrid.io"; // or your own node
const contractAddress = "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t"; // Example USDT
const myWatchAddressPadded = "000000000000000000000000" + myWatchAddressHex.slice(2);

async function fetchDeposits(fromBlock, toBlock) {
  const response = await fetch(`${endpoint}/v1/contracts/${contractAddress}/events`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      event_name: "Transfer",
      block_range: { start: fromBlock, end: toBlock },
      filters: { topic1: myWatchAddressPadded } // topic1 is usually 'to' address
    })
  });
  return response.json();
}
Enter fullscreen mode Exit fullscreen mode

This script doesn't spend anything. It asks the node, "Did anyone send tokens to this padded address between block X and block Y?"

As a rule, you don’t want to poll blindly from genesis. Maintain a cursor in your database storing the last processed block height. When your cron job or worker runs, it queries from last_processed_block + 1 to the current head.

Keep in mind that public RPC endpoints enforce rate limits. If your payment volume scales up, relying on shared infrastructure often leads to throttled requests and missed events. Many engineering teams eventually migrate to dedicated nodes or specialized providers like gf-pay.best to handle RPC traffic reliably when building out crypto checkout flows. Network conditions fluctuate, so having a fallback mechanism or a queue for failed RPC calls is standard practice.

Reconciliation and State Management

Detecting a transaction is only half the job. You must map it to a specific order in your database. This reconciliation process requires careful state management.

When generating a payment request, you usually assign a unique deposit address to the user, or you expect a precise amount to a shared pool address. If you use unique addresses per invoice (a common pattern derived from xpubs), reconciliation is straightforward: any deposit to address X belongs to invoice X.

If multiple users pay into a single watch-only address, you have to rely on exact amounts or memos. This gets messy fast because floating-point arithmetic and blockchain decimals rarely align perfectly. Users might send 10.000001 instead of 10.00. Your logic needs tolerances, usually defined by your business rules.

Once a transaction is spotted via RPC, update its status in your database:

  1. Pending: Transaction seen in the mempool or latest block.
  2. Confirming: Block depth increases. Most systems require a certain number of confirmations before crediting the user. On TRON, 19 confirmations are often cited as a standard threshold for finality, but you should verify current network parameters.
  3. Completed: Required confirmations reached. Trigger your webhook to fulfill the order.
  4. Failed/Orphaned: The chain reorganized, and the transaction dropped.

Never trust a zero-confirmation transaction for high-value settlements unless your risk model explicitly allows it. Chain reorganizations happen. A block you saw at height N might not be in the canonical chain five minutes later.

Designing the Payment UX

Backend reliability means nothing if the frontend confuses the user. Payment UX relies heavily on the speed and accuracy of your watch-only monitoring.

Users expect instant feedback. When they broadcast a transaction, their wallet says "Sent." But your system hasn't confirmed it yet. The UI should reflect this reality. Display a "Waiting for network confirmation..." state rather than jumping straight to "Processing" or leaving the user staring at a static spinner.

WebSockets are generally preferred over HTTP polling for the client-side experience. Your backend workers poll the RPC, update the database, and push an event via WebSocket to the specific client session. This keeps the UI snappy without forcing the user's browser to spam your API with "Is it there yet?" requests.

Also, handle edge cases gracefully. What happens if the user sends the wrong token to the watch-only address? What if they send it on the wrong network (e.g., sending ERC20 to a TRC20 address)? Your watch-only wallet will likely ignore it because the RPC filter targets a specific chain and contract. The user thinks they paid; your system sees nothing. Clear instructions on the checkout page specifying the exact network and token contract are mandatory, not optional.

Timeouts are another UX consideration. If a user generates an invoice but doesn't pay within 15 or 30 minutes, invalidate the address or lock the exchange rate. Leaving watch-only addresses open indefinitely complicates your reconciliation logic and exposes you to volatility risks.

Security Boundaries and Key Hygiene

The primary reason to use watch-only architectures is minimizing the blast radius of a breach. If an attacker gains root access to your payment processing server, they should find nothing but public keys and historical transaction logs.

Store private keys offline. Use hardware wallets or air-gapped machines for sweeping funds. When your watch-only wallet accumulates enough deposits, you construct an unsigned transaction on your hot server, move it to the cold environment via QR code or USB, sign it, and broadcast it.

Audit your dependencies. Cryptographic libraries evolve. Vulnerabilities in how an xpub is parsed or how an RPC payload is validated can introduce risks even in read-only systems. Treat your watch-only infrastructure with the same rigor as your signing infrastructure, because while it can't lose funds directly, it controls the information flow that triggers your business logic.

Conclusion

Watch-only wallets solve a fundamental problem in crypto software engineering: how to observe value transfer without holding the keys to the vault. By leveraging RPC polling, maintaining strict reconciliation state, and designing transparent user interfaces, developers can build robust payment systems. Keep your keys cold, your nodes synced, and your database cursors accurate.

Frequently Asked Questions

Can a watch-only wallet accidentally spend funds?
No. By definition, a watch-only wallet lacks the private keys or seed phrases required to cryptographically sign a transaction. Even if the software has a bug, it cannot authorize an outbound transfer. It can only read the blockchain state.

Do I need a full node to run a watch-only wallet?
Not strictly. You can use third-party RPC providers or lightweight SPV (Simplified Payment Verification) clients. However, running your own full node gives you complete control over indexing, removes reliance on external rate limits, and ensures you aren't being fed manipulated chain data.

How do I handle multiple blockchains with one watch-only setup?
Architecture varies significantly between chains. UTXO models (Bitcoin) use extended public keys to derive infinite addresses. Account models (Ethereum, TRON) monitor specific hex/base58 strings and parse internal transaction data or event logs. You usually need separate reconciliation workers tailored to each network's RPC specifications.

Top comments (0)