Skip to main content
Stellar RPC’s getEvents returns contract events from its recent window (up to about 7 days on Lumeus RPC; getHealth returns the oldest ledger). This recipe reads a contract’s events from a start ledger, pages with cursor, and keeps polling for new ones. For events older than the RPC window, use Follow a contract’s events on the Activity API. Set these once in your terminal. The sample values are real Testnet data, so the read examples return real results.
This recipe uses a busy Testnet lending pool:

Read and page

One event with xdrFormat: "json", trimmed:

Rules

  • Send startLedger on the first call only. Later calls send pagination.cursor from the previous result and repeat the same filters.
  • startLedger must be inside the RPC window: from oldestLedger to latestLedger, both returned by every getEvents call. Older ledgers return an error.
  • Save cursor after each page to resume after a restart. Deduplicate on the event id.
  • rpc retries 429 (rate_limited) and 503 (unavailable) after Retry-After, at most 5 times, and stops on any other error. Free allows 30 RPC requests a minute, so a fast catch-up can hit 429.
  • Without xdrFormat: "json", topics and values come as base64 XDR in topic and value.
See RPC methods for the filter limits and the page size.

Credits

On Testnet the follower is free: it costs 0 credits, and its 2,880 calls a day (one poll every 30 seconds) count toward your daily Testnet cap of 10,000 requests. On Mainnet, getEvents costs 2 credits plus 1 credit per started 64 KiB of response, so each poll costs at least 3. Polling every 30 seconds costs at least 8,640 credits a day, about 259,000 a month: slightly more than the Free plan’s 250,000, so poll less often on Free or use Starter. See RPC methods.

Next