> For the complete documentation index, see [llms.txt](https://docs.trustlesswork.com/trustless-work/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.trustlesswork.com/trustless-work/v2-en/escrow-js-sdk/runtimes.md).

# Runtimes

Use @trustless-work/escrow-js in Node, NestJS, Angular, and the browser.

One client, many runtimes. Prefer an **explicit** `TrustlessWorkClient` when your framework has DI.

### Node.js / Express

```ts
import {
  TrustlessWorkClient,
  development,
  toTrustlessWorkError,
  TrustlessWorkApiError,
} from "@trustless-work/escrow-js";

const client = new TrustlessWorkClient({
  baseURL: development,
  apiKey: process.env.API_KEY,
});

const page = await client.rest.listEscrows({ scope: "mine", limit: 20 });
```

### NestJS

Register the client as a provider:

```ts
import { Module } from "@nestjs/common";
import { TrustlessWorkClient, development } from "@trustless-work/escrow-js";

@Module({
  providers: [
    {
      provide: TrustlessWorkClient,
      useFactory: () =>
        new TrustlessWorkClient({
          baseURL: process.env.TW_BASE_URL ?? development,
          apiKey: process.env.TW_API_KEY,
          getAccessToken: async () => process.env.TW_ACCESS_TOKEN ?? null,
        }),
    },
  ],
  exports: [TrustlessWorkClient],
})
export class TrustlessWorkModule {}
```

Inject into services:

```ts
constructor(private readonly tw: TrustlessWorkClient) {}

async listMine() {
  return this.tw.rest.listEscrows({ scope: "mine" });
}
```

### Angular

Wrap the client in an `@Injectable` service:

```ts
import { Injectable } from "@angular/core";
import { from } from "rxjs";
import { TrustlessWorkClient, development } from "@trustless-work/escrow-js";

@Injectable({ providedIn: "root" })
export class TrustlessWorkService {
  private readonly client = new TrustlessWorkClient({
    baseURL: development,
    apiKey: "your-api-key",
    getAccessToken: () => localStorage.getItem("tw_token"),
  });

  listEscrows() {
    return from(this.client.rest.listEscrows({ scope: "mine", limit: 20 }));
  }

  getEscrow(contractId: string) {
    return from(this.client.graphql.getEscrow({ contractId }));
  }
}
```

### Browser (vanilla)

```html
<script type="module">
  import {
    TrustlessWorkClient,
    development,
  } from "https://esm.sh/@trustless-work/escrow-js@beta";

  const client = new TrustlessWorkClient({
    baseURL: development,
    apiKey: "YOUR_API_KEY",
  });

  const page = await client.rest.listEscrows({ scope: "mine", limit: 5 });
  console.log(page);
</script>
```

{% hint style="info" %}
Repo examples live under [`examples/`](https://github.com/Trustless-Work/trustlesswork-sdk-js/tree/main/examples) — `node-basic.ts`, `nestjs-provider.ts`, `angular-service.ts`, `browser-vanilla.html`.
{% endhint %}


---

# 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://docs.trustlesswork.com/trustless-work/v2-en/escrow-js-sdk/runtimes.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.
