Getting Started
Overview
The Trustless Work React SDK is a collection of hooks and typed entities.
It uses Axios for HTTP requests.
Quick links
Setup
Configure the provider
You’ll configure 2 things:
baseURL: usedevelopment(testnet) ormainNet(mainnet).apiKey: from the BackOffice dApp.
The SDK exports TrustlessWorkConfig. Wrap your app with it to enable all hooks.
"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>
);
}
If you render this provider on the server, hooks will break. Keep it in a client component.
Wrap your app
Pick the snippet that matches your setup.
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 and entities
You can now call SDK hooks from any component under the provider.
Typical flow:
Call a hook to get an unsigned XDR.
Sign the XDR with the correct role wallet.
Submit it with
useSendTransaction.
Read: useSendTransaction.
This SDK supports single-release and multi-release escrows. Use the correct hook + payload type for each flow.
Last updated