deployEscrow
Build an unsigned deploy transaction for a new single- or multi-release escrow.
Build an unsigned deploy transaction for a new v2 escrow. Returns unsignedXdr plus the predicted contractId.
Import
import { TrustlessWorkClient } from "@trustless-work/escrow-js";Signature
client.rest.deployEscrow(
payload: DeploySingleReleaseEscrowPayload | DeployMultiReleaseEscrowPayload,
type: EscrowType,
attribution?: AttributionHeaders,
): Promise<DeployEscrowResponse>Returns DeployEscrowResponse: { unsignedXdr, txHash, contractId }.
Single vs multi
DeploySingleReleaseEscrowPayload: signer, engagementId, title, description, amount, platformFee, roles (Roles), milestones (SingleReleaseMilestonePayload[]), trustline (DeployTrustline).
await client.rest.deployEscrow(payload, "single-release");DeployMultiReleaseEscrowPayload: same fields except no top-level amount; roles is MultiReleaseRoles; each milestone includes amount + receiver.
await client.rest.deployEscrow(payload, "multi-release");Example
import {
TrustlessWorkClient,
development,
toTrustlessWorkError,
TrustlessWorkApiError,
formatApiErrorMessage,
} from "@trustless-work/escrow-js";
import type { DeploySingleReleaseEscrowPayload } from "@trustless-work/escrow-js/types";
const client = new TrustlessWorkClient({
baseURL: development,
apiKey: process.env.API_KEY,
});
const onDeploy = async (payload: DeploySingleReleaseEscrowPayload) => {
try {
const { unsignedXdr, contractId } = await client.rest.deployEscrow(
payload,
"single-release",
{ platformId, subjectId },
);
const signedXdr = await signWithWallet(unsignedXdr);
const result = await client.rest.sendTransaction(signedXdr);
// Prefer predicted contractId; result.contractId may also appear on confirm
return { contractId, txHash: result.txHash };
} catch (error: unknown) {
const err = toTrustlessWorkError(error);
if (err instanceof TrustlessWorkApiError) {
console.error(formatApiErrorMessage(err));
}
throw error;
}
};See Operate and sendTransaction.