Runtimes
Use @trustless-work/escrow-js in Node, NestJS, Angular, and the browser.
One client, many runtimes. Prefer an explicit TrustlessWorkClient when your framework has DI.
Node.js / Express
import {
TrustlessWorkClient,
development,
toTrustlessWorkError,
TrustlessWorkApiError,
} from "@trustless-work/escrow-js";
const client = new TrustlessWorkClient({
baseURL: development,
apiKey: process.env.API_KEY,
});
const page = await client.rest.listEscrows({ scope: "mine", limit: 20 });NestJS
Register the client as a provider:
import { Module } from "@nestjs/common";
import { TrustlessWorkClient, development } from "@trustless-work/escrow-js";
@Module({
providers: [
{
provide: TrustlessWorkClient,
useFactory: () =>
new TrustlessWorkClient({
baseURL: process.env.TW_BASE_URL ?? development,
apiKey: process.env.TW_API_KEY,
getAccessToken: async () => process.env.TW_ACCESS_TOKEN ?? null,
}),
},
],
exports: [TrustlessWorkClient],
})
export class TrustlessWorkModule {}Inject into services:
Angular
Wrap the client in an @Injectable service: