Trustless Work
Spanish
Spanish
  • Bienvenido
  • Inicio
    • Guía rápida
    • Conceptos clave
    • Herramientas esenciales
  • ☀️Acerca de Trustless Work
    • Visión y misión
    • 🛤️Nuestro camino hasta ahora
      • 🤔El problema: orígen de Trustless Work
      • 👾El equipo se une
      • 💡La solución: escrows
      • 🏆Hitos clave
        • 🌠DraperU Stellar Astro Hacker House: un antes y un después
        • Lanzamiento de la API V1 en el Pura Vida ETH Hackathon
      • 🚀Programas actuales
        • 🌟DraperU Embark Program
        • 💻OD Hack Campaigns
      • 🛠️Desarrollo vertical
      • 🔮Visión a futuro
    • Equipo
  • ⚒️Descripción de la tecnología
    • 🚀Smart escrow API
    • ⛓️Smart contracts open-source de escrow
    • 📂Plantillas open-source y herramientas para desarrolladores
    • 💵USDC: La stablecoin detrás de Trustless Work
    • 🌟Stellar y Soroban: el motor de Trustless Work
  • 🌍Casos de uso: Escrow-as-a-service para cualquier industria
    • 🌎Proyecto destacado: Kindfi
  • 🤖Tutorial de Trustless Work Dapp
    • Paso 1: Accediendo a la Trustless Work Dapp e iniciando s
    • Paso 2: Creación de perfil y solicitud de clave API
    • Step 3: Crea un escrow
    • Step 4: Financiando un escrow
    • Paso 5: Marcando un hito como completo ✅
    • Paso 6: Aprobando el hito
    • Paso 7: Liberación del pago
    • Cómo obtener testnet tokens
  • 💻Developer Resources
    • Smart Escrow Design
      • What does a Smart Escrow "look like"?
      • Roles in Trustless Work
    • Escrow Lifecycle
      • Initiation Phase
      • Funding Phase
      • Complete phase
      • Approval phase
      • Release phase
      • Dispute Resolution
    • Referencia de API
      • Introduction
        • How to Integrate us
      • Deploy
        • Initialize Escrow
      • Autenticación
        • Request Api Key
      • Escrows
        • Schema
        • Fund Escrow
        • Get Escrow by Contract ID
        • Resolve Dispute
        • Change Milestone Status
        • Change Milestone Flag
        • Change Dispute Flag
        • Get Multiple Escrow Balance
        • Distribute Escrow Earnings
      • Helpers
        • Set Trustline
        • Send Transaction
    • Stellar Wallets
      • Freighter Wallet
      • Albedo Wallet
      • xBull Wallet
      • Rabet Wallet
      • Lobstr Wallet
      • Hana Wallet
      • Additional Resources
      • Troubleshooting & FAQs
  • 🫂Community and Roadmap
    • Community
      • Notion for Startups
      • Meru
    • Get Involved
    • 🛣️Roadmap: The Journey Ahead
  • 🎒Historical Context
    • 📜Escrow History:
      • 🗿Ancient to Colonial Era
      • 🏦Banking Era (19th - 20th Century)
      • 💻The Digital Era and Online Escrow
    • ⛓️Blockchain Era: Smart Escrows
  • 📢Appendices
    • Contact and Support
    • Links
      • ⚒️Trustless Work dApp
      • 🌐Trustless Work Website
      • 📣Telegram Chat
      • 💎Only Dust Profile
      • 👩‍💻Swagger for API
      • 📜Github
Powered by GitBook
LogoLogo

Links

  • Website
On this page

Was this helpful?

Export as PDF
  1. Developer Resources
  2. Referencia de API
  3. Introduction

How to Integrate us

Here you'll find the basic flow in order to use Trustless Work API. In this flows tutorial, we'll use as an example the integration of Trustless Work in our dApp.

PreviousIntroductionNextDeploy

Was this helpful?

Important Notes

Be sure to checkout the section for visual helpers.

  • We are using the Stellar Wallet Kit library.

  • We are using axios library with a pre-configuration with the Trustless Work URL and the Bearer token.

import axios from "axios";

const http = axios.create({
  baseURL: process.env.API_URL || "", // Trustless Work API URL
  timeout: 60000, // time
  headers: {
    "Content-Type": "application/json",
    Authorization: `Bearer ${process.env.API_KEY}`, // Trustless Work API Key
  },
});

export default http;
  • You should connect to your favorite wallet, if you are in development, Freighter is recommended.

  • You'll be able to see the Escrow entity in the page below.


Steps

  1. Initialize Escrow

The escrow contract must be deployed, which in turn initializes the escrow with its metadata.

Payload Type:

export type EscrowPayload = Omit<
  Escrow,
  "user" | "createdAt" | "updatedAt" | "id"
>;

Execute Endpoint:

interface EscrowPayloadWithSigner extends EscrowPayload {
  signer?: string;
}

export const initializeEscrow = async (
  payload: EscrowPayloadWithSigner,
) => {
  try {
  
    // Get the address
    const { address } = await kit.getAddress();
  
    // Add the signer
    const payloadWithSigner: EscrowPayloadWithSigner = {
      ...payload,
      signer: address,
    };

    // Execute the endpoint
    const response = await http.post(
      "/deployer/invoke-deployer-contract",
      payloadWithSigner,
    );

    // Get the unsigned transaction hash
    const { unsignedTransaction } = response.data;

    // Sign the transaction by wallet
    const { signedTxXdr } = await signTransaction(unsignedTransaction, {
      address,
      networkPassphrase: WalletNetwork.TESTNET,
    });

    // Send the transaction to Stellar Network
    const tx = await http.post("/helper/send-transaction", {
      signedXdr: signedTxXdr,
      returnValueIsRequired: true,
    });

    const { data } = tx;

    return data;
  } catch (error: unknown) {
    // catch code ...
  }
};

References:

  1. Fund Escrow

Each escrow must be funded before the release funds or resolve dispute. It's important to clarify that you can fund the escrow in any moment, but just for this case, we'll fund it in the beginning.

Payload Type:

export type FundEscrowPayload = Pick<Escrow, "amount" | "contractId"> & {
  signer: string;
};

Execute Endpoint:

export const fundEscrow = async (payload: FundEscrowPayload) => {
  try {
  
    // Get the address
    const { address } = await kit.getAddress();
  
    // Execute the endpoint
    const response = await http.post("/escrow/fund-escrow", payload);

    // Get the unsigned transaction hash
    const { unsignedTransaction } = response.data;

    // Sign the transaction by wallet
    const { signedTxXdr } = await signTransaction(unsignedTransaction, {
      address,
      networkPassphrase: WalletNetwork.TESTNET,
    });

    // Send the transaction to Stellar Network
    const tx = await http.post("/helper/send-transaction", {
      signedXdr: signedTxXdr,
    });

    const { data } = tx;
    return data;
  } catch (error: unknown) {
    // catch code...
  }
};

References:


These endpoints don't have any specific order to execute them

  1. Edit Milestones

You can edit the milestones in any moment, but just the Platform Entity will be able to do it. Only the pending milestones will be editable.

Payload Type:

export type EditMilestonesPayload = {
  contractId: string;
  escrow: EscrowPayload;
  signer: string;
};

Execute Endpoint:

export const editMilestones = async (payload: EditMilestonesPayload) => {
  try {
  
    // Get the address
    const { address } = await kit.getAddress();
  
    // Execute the endpoint
    const response = await http.put(
      "/escrow/update-escrow-by-contract-id",
      payload,
    );

    // Get the unsigned transaction hash
    const { unsignedTransaction } = response.data;

    // Sign the transaction by wallet
    const { signedTxXdr } = await signTransaction(unsignedTransaction, {
      address,
      networkPassphrase: WalletNetwork.TESTNET,
    });

    // Send the transaction to Stellar Network
    const tx = await http.post("/helper/send-transaction", {
      signedXdr: signedTxXdr,
    });

    const { data } = tx;
    return data;
  } catch (error: unknown) {
    // catch code...
  }
};

References:

ADD REFERENCES

  1. Change Milestone Status

With this endpoint you'll change the status of the milestones, but just the Service Provider will be able to do it.

Payload Type:

export type ChangeMilestoneStatusPayload = {
  contractId?: string;
  milestoneIndex: string;
  newStatus: MilestoneStatus; // you can custom your status
  serviceProvider?: string;
};

Execute Endpoint:

export const changeMilestoneStatus = async (
  payload: ChangeMilestoneStatusPayload,
) => {
  try {
  
    // Get the address
    const { address } = await kit.getAddress();
  
    // Execute the endpoint
    const response = await http.post(
      "/escrow/change-milestone-status",
      payload,
    );

    // Get the unsigned transaction hash
    const { unsignedTransaction } = response.data;

    // Sign the transaction by wallet
    const { signedTxXdr } = await signTransaction(unsignedTransaction, {
      address,
      networkPassphrase: WalletNetwork.TESTNET,
    });

    // Send the transaction to Stellar Network
    const tx = await http.post("/helper/send-transaction", {
      signedXdr: signedTxXdr,
    });

    const { data } = tx;
    return data;
  } catch (error: unknown) {
   // catch code...
  }
};

References:

  1. Change Milestone Flag

With this endpoint you'll approve the milestones, but just the Approver will be able to do it.

Payload Type:

export type ChangeMilestoneFlagPayload = Omit<
  ChangeMilestoneStatusPayload,
  "serviceProvider" | "newStatus"
> & {
  approver?: string;
  newFlag: boolean;
};

Execute Endpoint:

export const changeMilestoneFlag = async (
  payload: ChangeMilestoneFlagPayload,
) => {
  try {
  
    // Get the address
    const { address } = await kit.getAddress();
  
    // Execute the endpoint
    const response = await http.post(
      "/escrow/change-milestone-flag",
      payload,
    );

    // Get the unsigned transaction hash
    const { unsignedTransaction } = response.data;

    // Sign the transaction by wallet
    const { signedTxXdr } = await signTransaction(unsignedTransaction, {
      address,
      networkPassphrase: WalletNetwork.TESTNET,
    });

    // Send the transaction to Stellar Network
    const tx = await http.post("/helper/send-transaction", {
      signedXdr: signedTxXdr,
    });

    const { data } = tx;
    return data;
  } catch (error: unknown) {
   // catch code...
  }
};

References:

  1. Change Dispute Flag

In any moment, the approver or service provider can start a dispute. This cannot executed without funds in the escrow's balance.

Payload Type:

export type StartDisputePayload = Pick<Escrow, "contractId"> & {
  signer: string;
};

Execute Endpoint:

export const startDispute = async (
  payload: StartDisputePayload,
) => {
  try {
  
    // Get the address
    const { address } = await kit.getAddress();
  
    // Execute the endpoint
    const response = await http.post(
      "/escrow/change-dispute-flag",
      payload,
    );

    // Get the unsigned transaction hash
    const { unsignedTransaction } = response.data;

    // Sign the transaction by wallet
    const { signedTxXdr } = await signTransaction(unsignedTransaction, {
      address,
      networkPassphrase: WalletNetwork.TESTNET,
    });

    // Send the transaction to Stellar Network
    const tx = await http.post("/helper/send-transaction", {
      signedXdr: signedTxXdr,
    });

    const { data } = tx;
    return data;
  } catch (error: unknown) {
   // catch code...
  }
};

References:


Case #1: If all the milestones were completed and approved, you'll be able to release the funds.

  1. Distribute Escrow Earnings

When the escrow is ready to be released, you can do it with this endpoint. Only the release signer can do it.

Payload Type:

export type DistributeEscrowEarningsEscrowPayload = Pick<Escrow, "contractId"> &
  Partial<Pick<Escrow, "serviceProvider" | "releaseSigner">> & {
    signer: string;
  };

Execute Endpoint:

export const distributeEscrowEarnings = async (
  payload: DistributeEscrowEarningsEscrowPayload,
) => {
  try {
  
    // Get the address
    const { address } = await kit.getAddress();
  
    // Execute the endpoint
    const response = await http.post(
      "/escrow/distribute-escrow-earnings",
      payload,
    );

    // Get the unsigned transaction hash
    const { unsignedTransaction } = response.data;

    // Sign the transaction by wallet
    const { signedTxXdr } = await signTransaction(unsignedTransaction, {
      address,
      networkPassphrase: WalletNetwork.TESTNET,
    });

    // Send the transaction to Stellar Network
    const tx = await http.post("/helper/send-transaction", {
      signedXdr: signedTxXdr,
    });

    const { data } = tx;
    return data;
  } catch (error: unknown) {
   // catch code...
  }
};

References:

Case #2: If the approver or service provider started the dispute, you'll be able to resolve the dispute.

  1. Resolve Dispute

When the escrow is in dispute, you can resolve it with this endpoint. Only the dispute resolver can do it.

Payload Type:

export type ResolveDisputePayload = Pick<Escrow, "contractId"> &
  Partial<Pick<Escrow, "disputeResolver">> & {
    approverFunds: string;
    serviceProviderFunds: string;
  };

Execute Endpoint:

export const resolveDispute = async (
  payload: ResolveDisputePayload,
) => {
  try {
  
    // Get the address
    const { address } = await kit.getAddress();
  
    // Execute the endpoint
    const response = await http.post(
      "/escrow/resolving-disputes",
      payload,
    );

    // Get the unsigned transaction hash
    const { unsignedTransaction } = response.data;

    // Sign the transaction by wallet
    const { signedTxXdr } = await signTransaction(unsignedTransaction, {
      address,
      networkPassphrase: WalletNetwork.TESTNET,
    });

    // Send the transaction to Stellar Network
    const tx = await http.post("/helper/send-transaction", {
      signedXdr: signedTxXdr,
    });

    const { data } = tx;
    return data;
  } catch (error: unknown) {
   // catch code...
  }
};

References:

IMPORTANT NOTE

All endpoints related to escrow management return the transaction unsigned. This is done by means of a string returned in XDR (External Data Representation) format, which is a format that stellar uses to encode transactions. This string is what you should use to sign the transaction with the wallet of your choice. After being signed it will return the transaction signed in the same way by means of a string in XDR format.

  • This string is the one that must be sent to the next endpoint for the transaction to be sent to the Stellar network:

That's all, thanks.

💻
Stellar Wallets
Schema
Initialize Escrow
Initiation Phase
Fund Escrow
Funding Phase
Complete phase
Change Milestone Status
Approval phase
Change Milestone Flag
Change Dispute Flag
Release phase
Distribute Escrow Earnings
Dispute Resolution
Resolve Dispute
Smart Escrow Design
Welcome! | Stellar Wallets Kit
Logo
https://dev.api.trustlesswork.com/helper/send-transactiondev.api.trustlesswork.com