Skip to main content
IndexerClient is a thin HTTP client for a running @ankarachain/indexer service. It does not communicate with any blockchain directly — the indexer service handles chain polling and event normalization in the background. You use IndexerClient to query the event history it has indexed, and to manage webhook subscriptions that deliver new events to your application in real time.

Import


Constructor

string
required
The base URL of the running @ankarachain/indexer service, e.g. "http://localhost:4100" or "https://indexer.myapp.com". A trailing slash is stripped automatically.

Methods

queryEvents

Queries the indexer for on-chain events matching the given filter. Returns events oldest-first. Omitting filter (or passing an empty object) returns all indexed events up to the default limit.
string
Filter to events emitted by a specific contract address.
string
Filter by event type name, e.g. "opened", "liquidat", "delivered". Partial string matching may vary by indexer configuration.
number
Unix timestamp — only return events with timestamp >= since.
number
Maximum number of events to return. The indexer may cap this at its own configured maximum.
Returns: Promise<IndexedEvent[]>
string
Unique event identifier assigned by the indexer.
string
Address of the contract that emitted the event.
string
Normalized event type string, e.g. "opened", "funded", "liquidated".
number
Ledger number (Stellar) or block number (EVM) the event was included in.
string
Transaction hash of the transaction that emitted the event.
number
Unix timestamp of the ledger/block.
unknown
Event-specific decoded payload. Shape varies by event type — see the indexer service documentation for per-event schemas.

registerWebhook

Registers a new webhook subscription. The indexer will POST a JSON payload to url whenever any of the specified event types are indexed. The response includes a secret field — store it immediately, as it is shown only once and never returned again by listWebhooks().
string
required
The HTTPS endpoint to deliver event payloads to, e.g. "https://myapp.com/hooks/ankara".
string[]
required
Array of event type names to subscribe to, e.g. ["opened", "liquidated"]. Pass ["*"] to subscribe to all event types.
Returns: Promise<RegisteredWebhook>
string
Unique webhook ID. Use this to delete the webhook later.
string
The delivery URL as registered.
string[]
The event type list as registered.
string
A signing secret shown exactly once at registration time. The indexer includes this in an X-Ankara-Signature header on every delivery so you can verify the payload’s authenticity. Store it securely — it is not returned by listWebhooks().
number
Unix timestamp of webhook creation.
The secret field is returned only in the response from registerWebhook(). It is absent from all subsequent calls, including listWebhooks(). If you lose it, you must delete and re-register the webhook.

listWebhooks

Returns all registered webhooks. The secret field is not included in this response — only the id, url, events, and createdAt fields are returned.

removeWebhook

Deletes a registered webhook by its ID. Returns true if the webhook was successfully removed.
string
required
The id of the webhook to remove, as returned by registerWebhook() or listWebhooks().

Full Example


Webhook Payload Verification

The indexer signs every delivery with a X-Ankara-Signature header. Verify it in your webhook handler using the secret you saved at registration time.

Type Reference