> ## Documentation Index
> Fetch the complete documentation index at: https://docs.xdrcheck.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# A minimal replay adapter in TypeScript

> The adapter template in TypeScript, for an indexer in any language.

For authors of an indexer written in any language other than Go. After this page you have run a TypeScript adapter
against the corpus and know which places to change so that it drives your own indexer.

`adapter.ts` lets `xdrcheck replay` run the corpus against an indexer. It speaks the same JSON
protocol as the Go adapters (`xcc.adapter/1`, [docs/adapter-protocol.md](https://docs.xdrcheck.dev/reference/adapter-protocol.md)): one
JSON request per line on stdin, one response per line on stdout, logs on stderr. It is the TypeScript twin of
the Go template [`go/adapters/minimal`](https://docs.xdrcheck.dev/guides/go-indexer). Any program that reads and writes those JSON
lines works; TypeScript is the example.

It reports two observation kinds:

* **receipts**: how many transactions the indexer holds for each ledger;
* **transactions**: each transaction's hash, apply-order index, success and fee charged.

That is enough to catch an indexer that drops a ledger or a transaction, crashes, hangs or halts. Every other
kind is declared `not_applicable` and costs nothing.

## Run it

Node 24 runs the file as it is (type stripping, no build step). The one dependency is
`@stellar/stellar-sdk` 17.4.0, pinned by `package-lock.json`.

```sh theme={null}
cd examples/adapter-ts && npm ci --ignore-scripts && cd ../..
go/bin/xdrcheck replay --adapter "node examples/adapter-ts/adapter.ts" --selftest
go/bin/xdrcheck replay --adapter "node examples/adapter-ts/adapter.ts" --target-version 0.1.0 \
  --input sep54-dir --report reports/adapter-ts
```

`check.sh` (or `make check-adapter-ts`) does all three and fails when either check fails. Each failure, with what the ledger holds, what the
indexer held and the command that reproduces it, is in `reports/adapter-ts/REPORT.md`.

## Make it yours

The "indexer" here reads each ledger of the SEP-54 directory the harness serves and keeps its facts in memory.
Each place marked `REPLACE` is where your adapter calls your indexer instead:

1. **describe** (`DESCRIBE`): your adapter's name, the inputs your indexer reads (`sep54-dir`, `sep54-s3`,
   `rpc`), the protocol range it claims (`envelope`), and the kinds it models. Declare only what is true.
2. **prepare**: create a fresh, empty store for the session under `params.workdir`.
3. **ingest**: start your indexer on `params.input` and `params.range`, wait until its own progress marker
   reaches `range.end` or it stops, and report the facts behind the status (`completed`, `halted`, `crashed`,
   `timeout`; see adapter-protocol.md §4.3). Never decide a status from log text.
4. **observe**: one query per kind against your store, one fact per stored record, values exactly as stored. A
   ledger you hold nothing for is left out: that is how a drop is seen.
5. **teardown**: drop the store.

Then add kinds one at a time (participants, state changes, movements, addresses): each switches on that kind's
expectations for every entry. The JSON Schemas `corpus/schema/adapter-protocol.schema.json` and
`observation.schema.json` are the contract; `xdrcheck replay --selftest` validates every message against them.

When the selftest or the replay fails, the causes and fixes are the same as for the Go template
([go/adapters/minimal, "When it fails"](https://docs.xdrcheck.dev/guides/go-indexer.md#when-it-fails)). The adapter's stderr
is in the report directory's `logs/`.

Limits: `xdrcheck replay` runs on Linux only, and the harness judges only the kinds the adapter declares. The
template keeps its "indexer" in memory; your adapter must read back what your indexer stored, not what it was
sent.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.