> For the complete documentation index, see [llms.txt](https://plimsoll-protocol.gitbook.io/plimsoll-protocol-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://plimsoll-protocol.gitbook.io/plimsoll-protocol-docs/developers/sdk.md).

# TypeScript SDK

`@plimsoll/sdk` lives in `packages/sdk` of the app repo. It reads the contracts through RPC simulation, builds prepared transactions for writes, and wraps the indexer API. It never holds keys.

## Read coverage

```ts
import { PlimsollContracts, TESTNET, Tier, bpsToPercent, formatUnits } from "@plimsoll/sdk";

const plimsoll = new PlimsollContracts(TESTNET);
const sac = TESTNET.assets.PUSD.sac;

const cov = await plimsoll.coverage(sac, Tier.Transcribed);
// { bps: 10200, supply: 10000000000000n, reserves: 10200000000000n,
//   tier: 2, supplyLedger: 5034657, supplyTimestamp: 1791196882, reportAsOf: 1791158400 }

bpsToPercent(cov!.bps);        // "102.00%"
formatUnits(cov!.reserves);    // "1,020,000"
```

## Reference

### `PlimsollContracts`

| Method                                                                 | Returns                             |
| ---------------------------------------------------------------------- | ----------------------------------- |
| `getAsset(sac)`                                                        | `AssetRecord \| null`               |
| `getSupply(sac)`                                                       | `SupplySnapshot \| null`            |
| `getReport(sac, tier)`                                                 | `ReserveReport \| null`             |
| `coverage(sac, minTier)`                                               | `Coverage \| null`                  |
| `isCovered(sac, minBps, maxAgeSeconds, minTier)`                       | `boolean`                           |
| `getReporter(address)`                                                 | `ReporterInfo \| null`              |
| `prepareListAsset(source, sac)`                                        | unsigned XDR                        |
| `prepareDeploySac(source, code, issuer)`                               | unsigned XDR                        |
| `preparePostReserve({ reporter, sac, amount, asOf, docHash, docUri })` | unsigned XDR                        |
| `submit(signedXdr)`                                                    | transaction hash, after it succeeds |

A failed simulation throws `ContractCallError`, whose message contains the contract error, e.g. `Error(Contract, #5)` for `NotReporter`.

### Posting a report

```ts
import { parseUnits, sha256Hex } from "@plimsoll/sdk";
import { signTransaction } from "@stellar/freighter-api";

const xdr = await plimsoll.preparePostReserve({
  reporter: issuer,
  sac,
  amount: parseUnits("1,020,000"),
  asOf: Date.UTC(2026, 9, 5) / 1000,
  docHash: await sha256Hex(await file.arrayBuffer()),
  docUri: "https://example.com/reserves/2026-10.pdf",
});
const { signedTxXdr } = await signTransaction(xdr, {
  networkPassphrase: TESTNET.networkPassphrase,
  address: issuer,
});
const hash = await plimsoll.submit(signedTxXdr);
```

### `IndexerClient`

| Method                       | Endpoint                                |
| ---------------------------- | --------------------------------------- |
| `listAssets(minTier?)`       | `GET /v1/assets`                        |
| `getAsset(sac, minTier?)`    | `GET /v1/assets/{sac}`                  |
| `supplyHistory(sac, limit?)` | `GET /v1/assets/{sac}/supply`           |
| `reportHistory(sac, limit?)` | `GET /v1/assets/{sac}/reports`          |
| `reporters()`                | `GET /v1/reporters`                     |
| `network()`                  | `GET /v1/network`                       |
| `breakdown(hash)`            | `GET /v1/breakdowns/{hash}` (raw bytes) |

### Helpers

| Function                                       | Example                                        |
| ---------------------------------------------- | ---------------------------------------------- |
| `formatUnits(10200000000000n)`                 | `"1,020,000"`                                  |
| `parseUnits("1.5")`                            | `15000000n`                                    |
| `bpsToPercent(9990)`                           | `"99.90%"`                                     |
| `coverageStatus(bps, ageSeconds)`              | `"covered" \| "under" \| "stale" \| "unknown"` |
| `sacAddress(code, issuer, passphrase)`         | the asset's SAC address                        |
| `sha256Hex(bytes)` / `matchesHash(bytes, hex)` | document checks                                |

## Tests

```bash
npm test                      # unit tests
PLIMSOLL_LIVE=1 npm test      # plus reads against the live testnet contracts
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://plimsoll-protocol.gitbook.io/plimsoll-protocol-docs/developers/sdk.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
