Last updated
Edit

Look Up Checks

This tutorial shows how to look up Checks by their sender or recipient, in JavaScript.

Prerequisites

  • You should be familiar with the basics of using the xrpl.js client library.
  • To get any results, the addresses you're looking up must have at least one Check entry in the ledger. See also: Send a Check.

Source Code

The complete source code for this tutorial is available in the source repository for this website:

Checks sample code

Steps

1. Look up all Checks for the address

To get a list of all incoming and outgoing Checks for an account, use the account_objects command and set the type field of the request to checks. You may need to make multiple requests if the result is paginated.

    // Loop through account objects until marker is undefined -----------------
    let current_marker = null
    let checks_found = []
    do {
      const request = {
        "command": "account_objects",
        "account": "rGPnRH1EBpHeTF2QG8DCAgM7z5pb75LAis",
        "ledger_index": "validated",
        "type": "check"
      }

      if (current_marker) {
        request.marker = current_marker
      }

      const response = await client.request(request)
      
      checks_found = checks_found.concat(response.result.account_objects)
      current_marker = response.result.marker

    } while (current_marker)

    

2. Filter the responses by recipient

The response may include Checks where the account from the request is the sender or the recipient. Each member of the account_objects array of the response represents one Check. For each such Check object, the address in the Destination is address of that Check's recipient, such as in the following code:

    // Filter results by recipient --------------------------------------------
    // To filter by sender, check Account field instead of Destination
    const checks_by_recipient = []
    for (const check of checks_found) {
      if (check.Destination == "rGPnRH1EBpHeTF2QG8DCAgM7z5pb75LAis") {
        checks_by_recipient.push(check)
      }
    }
    
    // Print results ----------------------------------------------------------
    if (checks_by_recipient.length === 0) {
      console.log("No checks found.")
    } else {
      console.log("Checks: \n", JSON.stringify(checks_by_recipient, null, 2))
    }

    

To filter by sender, check the address in the Account field of the Check instead.

tip
For each Check entry in the results, the Check's ID is in the index field. You'll need this value to cash or cancel the Check.