> 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-react-sdk/getting-started.md).

# Getting Started

## Getting Started

#### Overview

The Trustless Work React SDK exposes typed hooks and a thin client over Core API v2.

{% hint style="info" %}
Write flows typically need an API key (`NEXT_PUBLIC_API_KEY`). Optional wallet-session auth uses `getAccessToken`.
{% endhint %}

#### Quick links

<table data-view="cards"><thead><tr><th>Title</th><th data-card-target data-type="content-ref">Link</th></tr></thead><tbody><tr><td>NPM package</td><td><a href="https://www.npmjs.com/package/@trustless-work/escrow">https://www.npmjs.com/package/@trustless-work/escrow</a></td></tr><tr><td>Architecture</td><td></td></tr><tr><td>Send signed XDR</td><td></td></tr></tbody></table>

#### Setup

{% stepper %}
{% step %}

#### Installation

Install the SDK (v5 / Core API v2).

{% tabs %}
{% tab title="npm" %}

```sh
npm install @trustless-work/escrow@5
```

{% endtab %}

{% tab title="yarn" %}

```sh
yarn add @trustless-work/escrow@5
```

{% endtab %}

{% tab title="pnpm" %}

```sh
pnpm add @trustless-work/escrow@5
```

{% endtab %}
{% endtabs %}

Peer dependencies: `react` and `react-dom` `>=18 <20`.

{% hint style="info" %}
If you publish/install under an npm dist-tag (e.g. `beta`), use that tag instead of `@5` so `latest` can stay on the audited Core v1 line.
{% endhint %}
{% endstep %}

{% step %}

#### Configure the provider

Wrap your app with `TrustlessWorkConfig`.

| Prop             | Role                                                         |
| ---------------- | ------------------------------------------------------------ |
| `baseURL`        | Core API host (`development` / `mainNet`, or any URL string) |
| `apiKey`         | `x-api-key` header                                           |
| `getAccessToken` | Optional Bearer token getter (re-read per request)           |
| `defaultHeaders` | Merged into every request (e.g. `X-TW-Platform`)             |

{% code title="src/trustless-work-provider.tsx" overflow="wrap" fullWidth="true" %}

```typescript
"use client";

import React from "react";
import {
  development,
  TrustlessWorkConfig,
} from "@trustless-work/escrow";

interface TrustlessWorkProviderProps {
  children: React.ReactNode;
}

export function TrustlessWorkProvider({
  children,
}: TrustlessWorkProviderProps) {
  const apiKey = process.env.NEXT_PUBLIC_API_KEY || "";

  return (
    <TrustlessWorkConfig baseURL={development} apiKey={apiKey}>
      {children}
    </TrustlessWorkConfig>
  );
}
```

{% endcode %}

{% hint style="warning" %}
Keep the provider in a **client** component. If you render it on the server, hooks will break.
{% endhint %}
{% endstep %}

{% step %}

#### Wrap your app

{% tabs %}
{% tab title="Next.js (App Router)" %}

```typescript
import { TrustlessWorkProvider } from "@/trustless-work-provider";

export default function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <html lang="en">
      <body>
        <TrustlessWorkProvider>{children}</TrustlessWorkProvider>
      </body>
    </html>
  );
}
```

{% endtab %}

{% tab title="React (SPA)" %}

```typescript
import { TrustlessWorkProvider } from "./trustless-work-provider";

export function App() {
  return (
    <TrustlessWorkProvider>
      <YourApp />
    </TrustlessWorkProvider>
  );
}
```

{% endtab %}
{% endtabs %}
{% endstep %}

{% step %}

#### Use hooks

Typical **operate** flow:

1. Call a hook to get an **unsigned XDR** (and for deploy, a predicted `contractId`).
2. Sign the XDR with the correct role wallet.
3. Submit with `useSendTransaction`.

For **reads**, pair hooks with TanStack Query — hooks return imperative functions, not React Query wrappers.

See useSendTransaction and Architecture.
{% endstep %}
{% endstepper %}

#### Without React

```typescript
import { TrustlessWorkClient, development } from "@trustless-work/escrow";

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

await client.rest.listEscrows({ scope: "mine", limit: 20 });
await client.graphql.getEscrow({ contractId });
```

{% hint style="success" %}
This SDK supports **single-release** and **multi-release** escrows. Use the correct payload type and `EscrowType` for each flow.
{% 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.trustlesswork.com/trustless-work/v2-en/escrow-react-sdk/getting-started.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
