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

Getting Started

Install @trustless-work/escrow-js and create a TrustlessWorkClient.

Overview

The Trustless Work JavaScript SDK is a typed, framework-agnostic client over Core API v2. It uses native fetch (Node 18+ / browsers) — no Axios, no React peers.

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

Title

Architecture

Title

Send signed XDR

Title

Runtimes

Setup

1

Installation

npm i @trustless-work/escrow-js@beta

Requires Node.js ≥ 18 (global fetch). Zero runtime dependencies.

Install under the beta dist-tag while Core v2 is in beta, so latest can stay on the audited Core v1 line for other packages.

2
import { TrustlessWorkClient, development } from "@trustless-work/escrow-js";

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

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

This is the preferred pattern for NestJS / Angular DI and server apps.

3

Or configure a default client

Vanilla equivalent of React’s TrustlessWorkConfig:

import {
  configureTrustlessWork,
  escrowRest,
  escrowGraphql,
  development,
} from "@trustless-work/escrow-js";

configureTrustlessWork({
  baseURL: development,
  apiKey: process.env.API_KEY,
  getAccessToken: async () => sessionToken,
  defaultHeaders: { "X-TW-Platform": platformId },
});

await escrowRest().listEscrows({ scope: "mine", limit: 20 });
await escrowGraphql().getEscrow({ contractId: "C..." });
4

Build → sign → send

Typical operate flow:

  1. Call a REST method to get an unsigned XDR (and for deploy, a predicted contractId).

  2. Sign the XDR with the correct role wallet.

  3. Submit with sendTransaction.

For reads, call REST or GraphQL methods directly — they return Promises (pair with your own cache if needed).

Client options

Option
Role

baseURL

Core API host (development / mainNet, or any URL string)

apiKey

x-api-key header

getAccessToken

Optional Bearer getter — sync or Promise (re-read per request)

defaultHeaders

Merged into every request (e.g. X-TW-Platform)

fetch

Optional custom fetch (tests, polyfills, undici)

timeoutMs

Optional timeout via AbortSignal.timeout

Next steps

  • Architecture — entry points and layers

  • Operate — mutate methods

  • REST Reads — GET /escrows*

  • Runtimes — Node, NestJS, Angular, browser

  • Errors — Problem Details helpers

Last updated