Getting Started
Getting Started
Overview
The Trustless Work React SDK exposes typed hooks and a thin client over Core API v2.
Quick links
Architecture
Send signed XDR
Setup
Configure the provider
Wrap your app with TrustlessWorkConfig.
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)
"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>
);
}Keep the provider in a client component. If you render it on the server, hooks will break.
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>
);
}Use hooks
Typical operate flow:
Call a hook to get an unsigned XDR (and for deploy, a predicted
contractId).Sign the XDR with the correct role wallet.
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 });This SDK supports single-release and multi-release escrows. Use the correct payload type and EscrowType for each flow.
Last updated