circle-check
Our docs are AI-ready. Use them as context for any AI, or ask questions via the search bar.

flag-checkeredGetting Started

Overview

The Trustless Work React SDK is a collection of hooks and typed entities.

It uses Axiosarrow-up-right for HTTP requests.

circle-info

Write flows require an API key (NEXT_PUBLIC_API_KEY). Read-only calls can work without one.

Setup

1

Installation

Install the SDK.

npm install "@trustless-work/escrow"
2

Configure the provider

You’ll configure 2 things:

  • baseURL: use development (testnet) or mainNet (mainnet).

  • apiKey: from the BackOffice dApp.

The SDK exports TrustlessWorkConfig. Wrap your app with it to enable all hooks.

src/trustless-work-provider.tsx
"use client"; // make sure this is a client component

import React from "react";
import {
  // development environment = "https://dev.api.trustlesswork.com"
  development,

  // mainnet environment = "https://api.trustlesswork.com"
  mainNet,
  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>
  );
}
circle-exclamation
3

Wrap your app

Pick the snippet that matches your setup.

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

Use hooks and entities

You can now call SDK hooks from any component under the provider.

Typical flow:

  1. Call a hook to get an unsigned XDR.

  2. Sign the XDR with the correct role wallet.

  3. Submit it with useSendTransaction.

Read: useSendTransaction.

circle-check

Last updated

Was this helpful?