PollarPollarDemo

Products

AuthenticationWalletTransactions

Integrations

KYCSoonRampNewSwapNewEarnNew

Wallet Adapters

Stellar Wallets KitPrivyNew

Adapters

Trustless Work

Built with Pollar

LumenWipeNew
OverviewImplementationAdapter

The Trustless Work adapter

How Trustless Work plugs into Pollar. The adapter is plain client-side code: it calls the protocol, gets back an unsigned transaction, and hands it to Pollar to sign and submit.

The adapter contract

Every adapter function returns { unsignedTransaction: string }. Pollar signs and submits it with the user's connected wallet — no secret key or API key ever touches the frontend.

adapter.ts

The full adapter definition. Each method calls the protocol and returns the unsigned XDR.

adapter.ts
import { type AdapterFn } from '@pollar/core';
import { createPollarAdapterHook } from '@pollar/react';

const TW_API = 'https://dev.api.trustlesswork.com';

async function tw<T>(
  path: string,
  body: T,
): Promise<{ unsignedTransaction: string }> {
  const res = await fetch(`${TW_API}${path}`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify(body),
  });
  if (!res.ok) {
    const err = await res.json().catch(() => ({}));
    throw new Error(err?.message ?? `TrustlessWork error: ${res.status}`);
  }
  return res.json();
}

export type TrustlessWorkAdapter = {
  deployEscrow: AdapterFn<DeployEscrowParams>;
  fundEscrow: AdapterFn<FundEscrowParams>;
  approveMilestone: AdapterFn<ApproveMilestoneParams>;
  releaseFunds: AdapterFn<ReleaseFundsParams>;
  initiateDispute: AdapterFn<InitiateDisputeParams>;
  resolveDispute: AdapterFn<ResolveDisputeParams>;
};

export const trustlessWorkAdapter: TrustlessWorkAdapter = {
  deployEscrow:     (p) => tw('/escrow/initialize-escrow', p),
  fundEscrow:       (p) => tw('/escrow/fund-escrow', p),
  approveMilestone: (p) => tw('/escrow/approve-milestone', p),
  releaseFunds:     (p) => tw('/escrow/complete-escrow', p),
  initiateDispute:  (p) => tw('/escrow/dispute-escrow', p),
  resolveDispute:   (p) => tw('/escrow/resolute-dispute', p),
};

Register it once

Register the adapter on the Pollar provider and derive a typed hook with createPollarAdapterHook. From then on any component can call it, and Pollar owns the signing.

app setup
// 1. register the adapter on the Pollar provider
<PollarProvider
  apiKey={apiKey}
  adapters={{ escrow: trustlessWorkAdapter }}
>
  {children}
</PollarProvider>

// 2. derive a typed hook once, at module scope
export const useEscrow =
  createPollarAdapterHook<TrustlessWorkAdapter>('escrow');