For the complete documentation index, see llms.txt. This page is also available as Markdown.

Reading and subscribing to Transactions

In this session, we'll demonstrate how to coordinate using the XRPL.

The XRPL is a public ledger, meaning that when you write on-chain, anyone can read it. In this session, we will demonstrate how to subscribe to events as they happen on-chain.

First, we will create a pair of accounts:

index.ts
import xrpl from "xrpl";

const serverURL = "wss://s.altnet.rippletest.net:51233"; // For testnet

const main = async () => {
  const client = new xrpl.Client(serverURL)
  await client.connect()

  // do something useful
  console.log("lets fund 2 accounts...")
  const { wallet: wallet1, balance: balance1 } = await client.fundWallet()
  const { wallet: wallet2, balance: balance2 } = await client.fundWallet()

  console.log({ wallet1, balance1 })
  console.log({ wallet2, balance2 })

  // end
  client.disconnect()
};

main()

Check the logs to find the seed for both accounts. We will use these later to reuse the accounts deterministically.

Creating a payment transaction

Here is how to generate a payment transaction between the two accounts.

Reading transactions

One way to retrieve transactions for a given account is to create a request for transactions. Here is an example

Listening for transactions

Finally, we will demonstrate how to listen for transactions affecting a given account to catch all transactions.

You can subscribe to an account, to trigger on each transaction for instance. This is how you would listen to a specific account.

Last updated