Files
xrpl-dev-portal/content/tutorial-checks-lookup-by-sender.md

2.6 KiB

Look up Checks by sender address

This tutorial shows how to look up Checks by their sender. You may also want to look up Checks by recipient.

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 with the sending account's address and set the type field of the request to checks.

Note: The commandline interface to the account_objects command does not accept the type field. You can use the json command to send the JSON-RPC format request on the commandline instead.

Caution: RippleAPI does not have built-in support for the account_objects method. You can make a raw request in the WebSocket format using the api.connection.request(websocket_request_json) method. The response to this method is in the rippled API format. (For example, XRP is specified in integer "drops" rather than as a decimal.)

Example Request

RippleAPI

{% include 'code_samples/checks/js/getChecks.js' %}

JSON-RPC

{% include 'code_samples/checks/json-rpc/account_objects-req.json' %}

Example Response

RippleAPI

{% include 'code_samples/checks/js/get-checks-resp.txt' %}

JSON-RPC

200 OK

{% include 'code_samples/checks/json-rpc/account_objects-resp.json' %}

2. Filter the responses by sender

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

The following pseudocode demonstrates how to filter the responses by sender:

sender_address = "rBXsgNkPcDN2runsvWmwxk3Lh97zdgo9za"
account_objects_response = get_account_objects({
    account: sender_address,
    ledger_index: "validated",
    type: "check"
})

for (i=0; i < account_objects_response.account_objects.length; i++) {
  check_object = account_objects_response.account_objects[i]
  if (check_object.Account == sender_address) {
    log("Check from sender:", check_object)
  }
}

{% include 'snippets/tx-type-links.md' %}