Build with xrpl.js· 4 of 4

Read and listen

Ask the ledger questions, then subscribe for news. After a reconnect, fill the gap.

5 minMedium

Key points

  • account_info, account_lines and tx answer one question each.
  • subscribe pushes each new transaction for the accounts you watch.
  • If the link drops, subscribe again and fetch what you missed.

The lesson

  1. A program can ask the ledger, or listen to it.

  2. Asking is a question with one answer:

    • account_info: what is this account's balance?
    • account_lines: which trust lines does it hold?
    • tx: what happened to this transaction?
  3. Ask for the validated ledger when the answer must be final.

  4. Listening is a subscription. You say which accounts to watch. The server then pushes each new transaction as it happens, like a doorbell. No need to keep asking.

  5. Connections . Wi-Fi blinks, servers restart. xrpl.js reconnects by itself, but the server has forgotten your subscription. So on every reconnect, do two things:

    1. Subscribe again.
    2. Backfill: ask for the transactions you missed while you were away.
  6. Remember which transactions you already handled, and skip repeats.

Check yourself3 questions
1. Which request lists an account's trust lines?
2. The connection drops for a minute. What should the program do after?
3. A stream message has validated false. What should you do?