Params (5)
number
Ledger sequence number to start fetching responses from (inclusive). This method will return an error if
startLedger is less than the oldest ledger stored in this node, or greater than the latest ledger seen by this node. If a cursor is included in the request, startLedger must be omitted.Sequence number of the ledger.number
Ledger sequence number represents the end of search window (exclusive). If a cursor is included in the request,
endLedger must be omitted.Sequence number of the ledger.object[]
List of filters for the returned events. Events matching any of the filters are included. To match a filter, an event must match both a contractId and a topic. Maximum 5 filters are allowed per request.
object
Pagination in stellar-rpc is similar to pagination in Horizon. See Pagination.
string
Lets the user choose the format in which the response should be returned - either as unpacked JSON or as base64-encoded XDR strings. Note that you should not rely on any schema for the JSON, as it will change when the underlying XDR changes.Specifies whether XDR should be encoded as Base64 (default or βbase64β) or JSON (βjsonβ).
Result
(getEventsResult)number
The sequence number of the latest ledger known to Stellar RPC at the time it handled the request.
number
The sequence number of the oldest ledger ingested by Stellar RPC at the time it handled the request.
string
The unix timestamp (as a string) of the close time of the latest ledger known to Stellar RPC when it handled the request.
string
The unix timestamp (as a string) of the close time of the oldest ledger kept in history by Stellar RPC when it handled the request.
object[]
string
A token which can be included in a subsequent request to obtain the next page of results.
Examples
- Native XLM Transfer Events
- All Events
Example request to the Result
getEvents method, filtering for transfer events for native Lumens and limiting the number of returned events to 2.RequestEvent ordering
getEvents returns events in ascending order of their id. The id holds a TOID and an event index, so the sort key is the ledger sequence, then the transaction index, then the operation index, then the event index.
Protocol 23 keeps events in two separate XDR fields. TransactionMetaV4.events holds the transaction-level events. Each OperationMetaV2.events holds the events of one operation. A transaction-level event also carries a stage, because these events happen at different points of the ledger apply flow. Operation events all happen when the transaction is applied.
Stellar RPC re-derives the execution order of Stellar Core and builds each cursor from it:
A TOID gives 12 bits to the operation index and 20 bits to the transaction index.
4095 is therefore the largest operation index, which sorts an AFTER_TX event after every operation of its transaction. 1048575 is the largest transaction index, which sorts an AFTER_ALL_TXS event after every transaction of the ledger. Transaction indexes start at 1, so index 0 sorts before every transaction of the ledger.
Events in one ledger come back in this order:
- Every fee charge event.
- For each transaction, in transaction order: its operation events, then its post-transaction events.
- Every fee refund event.
getTransaction and getTransactions methods return the two XDR fields separately, in their events object, as events.transactionEventsXdr and events.contractEventsXdr.
transactionIndex and operationIndex come from the cursor. On a transaction-level event they hold the sort values in the table above, not a real position in the ledger. Read txHash to find the transaction that a fee event belongs to.BEFORE_ALL_TXS stage. It emits a Soroban fee refund at the AFTER_ALL_TXS stage. Both are contract events from the native asset contract, and their topics are the symbol fee and the fee source address. A refund carries a negative amount. Stellar Core emits no event when the amount is zero.
Those are the decoded values. This method returns topic and value as base64 ScVals unless you set xdrFormat to json. A topic filter therefore takes the encoded symbol, AAAADwAAAANmZWUA, and not the string fee.
Using the Lab
Letβs test the example request for Native XLM Transfer Events directly on the Stellar Laboratory. The new Lab supports sharable URLs that prefill input fields based on query parameters. This makes it easy to share and revisit specific configurations. π View Native XLM Transfer Events example on the Lab