For the complete documentation index, see llms.txt. This page is also available as Markdown.

Getting Started

Getting Started

Overview

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

Write flows typically need an API key (NEXT_PUBLIC_API_KEY). Optional wallet-session auth uses getAccessToken.

Title

Architecture

Title

Send signed XDR

Setup

1

Installation

Install the SDK (v5 / Core API v2).

npm i @trustless-work/escrow@beta

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

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.

2

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)

src/trustless-work-provider.tsx
"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>
  );
}
3

Wrap your app

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

export default function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <html lang="en">
      <body>
        <TrustlessWorkProvider>{children}</TrustlessWorkProvider>
      </body>
    </html>
  );
}
import { TrustlessWorkProvider } from "./trustless-work-provider";

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

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.

Without React

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 });

Last updated