Skip to main content
Beta featureThe queryEvents method is available only on RPC nodes that enable it’s new storage engine, which is currently in beta. Standard Stellar RPC nodes do not support this method. To use it, run RPC from the archive-node-beta tag or connect to a provider that offers one.This method is in beta and may change before general availability.
Returns contract and system events that match the specified filters within a ledger range. Results are paginated; each response contains a page of events and, when the scan is not complete, a cursor for continuing the query. Set order to asc to scan forward from minLedger, or to desc to scan backward from maxLedger. If omitted, maxLedger defaults to the latest ledger. To start a query, specify the applicable ledger bounds, scan order, and optional filters. To retrieve the next page, send the cursor returned in the previous response without repeating minLedger, maxLedger, order, or filters. The cursor preserves those query parameters. limit and xdrFormat are not stored in the cursor and may be specified on each request. Use scanStatus to determine whether to request another page, wait for additional ledgers, or stop. An empty events array does not necessarily mean the scan is complete.

Params (7)

Please note that parameter structure within the request must contain named parameters as a by-name object, and not as positional arguments in a by-position array
number
The first ledger in the range (inclusive). Required for ascending scans (order: asc) and optional for descending scans. Specify this parameter only when starting a query, not when continuing with a cursor.Sequence number of the ledger.
number
The last ledger in the range (inclusive). Optional. Without maxLedger, an ascending scan continues toward newly closed ledgers and reports WAITING_FOR_LEDGERS when it catches up to the chain. A descending scan starts at the latest ledger. Specify this parameter only when starting a query.Sequence number of the ledger.
string
The direction of the scan. asc (default) scans forward from minLedger; desc scans backward from maxLedger. Specify this parameter only when starting a query.Available options: asc, desc
object[]
An array of 1 to 256 event filters. An event matches if it satisfies at least one filter; within a filter, all specified fields must match. Omit filters to match all events. Specify this parameter only when starting a query.For example, to match either transfer or mint events from one contract, send two filters with the same contractId and a different topic0. The first example below does this.Topic values are Base64-encoded XDR ScVals, not plain strings. Use the JSON to XDR page in the Lab to encode a value.A query may use at most 15 distinct index terms by default; node operators can configure this limit. Each distinct contractId is one term, each distinct type is one term, and each distinct value at a given topic position is one term. The same value at the same position counts once no matter how many filters repeat it. The same value at two different positions counts twice. For example, [{ topic0: transfer, topic1: me }, { topic0: transfer, topic2: me }] uses 3 terms. A query over the budget returns invalid_params with termsUsed and termBudget in error.data.
string
The cursor returned by the previous response, used to continue a query. It preserves the ledger bounds, scan order, and filters. Do not combine cursor with minLedger, maxLedger, order, or filters; doing so returns an error.
number
The maximum number of events to return per page, from 1 to 1,000. Defaults to 100. This setting is not stored in the cursor; include it on each request to retain a nondefault value.
string
Controls how XDR values are represented in the response: decoded JSON or Base64-encoded XDR. Do not depend on a fixed schema for the JSON representation, as it may change with the underlying XDR.Specifies whether XDR should be encoded as Base64 (default or ‘base64’) or JSON (‘json’).

Result

(queryEventsResult)
object[]
required
Events returned on this page, up to the configured limit. The array may be empty even when more pages remain; check scanStatus.
string
An opaque cursor for retrieving the next page. It preserves the original ledger bounds, scan order, and filters and does not expire. The cursor is absent only when scanStatus is COMPLETE.
string
required
Indicates the state of the scan and the next action.
  • HAS_MORE: more data can be scanned immediately; request the next page.
  • WAITING_FOR_LEDGERS: the scan needs ledgers the node does not yet hold; wait and retry with the same cursor.
  • OLDEST_REACHED: a descending scan reached the oldest ledger available on this node before reaching the requested lower bound; stop or use a node with deeper history.
  • COMPLETE: the requested range has been fully scanned; no cursor is returned.
Available options: HAS_MORE, WAITING_FOR_LEDGERS, OLDEST_REACHED, COMPLETE
number
required
A scan checkpoint indicating that all matching events from the scan’s starting bound through this ledger have been delivered. If a page ends partway through a ledger, this field identifies the last fully scanned ledger; the cursor resumes within the partially scanned ledger. Before any ledger has been fully scanned, the value is minLedger - 1 for ascending scans or maxLedger + 1 for descending scans.
number
required
The sequence number of the oldest ledger available to the RPC node when it processed the request.
number
required
The sequence number of the latest ledger known to the RPC node when it processed the request.

Examples

Starts a query for the newest transfer or mint events from one contract, two per page. With order: desc and no ledger bounds, the scan starts at the latest ledger and walks back. The two filters share a contractId and differ in topic0, so an event matches either. Ledger numbers and hashes are illustrative.Request
Result

Errors

Invalid requests return JSON-RPC error code -32602. Because the human-readable error message may vary, use error.data.reason to identify the cause. Additional fields in error.data depend on the reason. Other failures return a JSON-RPC internal error without additional error data.